找不到由颤动产生的活动

时间:2019-03-21 06:37:59

标签: android flutter

堆栈如下:

2019-03-21 14:23:50.883 10148-10148/com.qiangxi.wx_assistant_flutter E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.qiangxi.wx_assistant_flutter, PID: 10148
    java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.qiangxi.wx_assistant_flutter/com.qiangxi.wx_assistant_flutter.activity.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "com.qiangxi.wx_assistant_flutter.activity.MainActivity" on path: DexPathList[[zip file "/data/app/com.qiangxi.wx_assistant_flutter-HTuMLA_86hLW95aeKW4w3g==/base.apk"],nativeLibraryDirectories=[/data/app/com.qiangxi.wx_assistant_flutter-HTuMLA_86hLW95aeKW4w3g==/lib/arm64, /data/app/com.qiangxi.wx_assistant_flutter-HTuMLA_86hLW95aeKW4w3g==/base.apk!/lib/arm64-v8a, /system/lib64, /vendor/lib64]]
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2847)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3033)
        at android.app.ActivityThread.-wrap11(Unknown Source:0)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1734)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:192)
        at android.app.ActivityThread.main(ActivityThread.java:6811)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:817)
     Caused by: java.lang.ClassNotFoundException: Didn't find class "com.qiangxi.wx_assistant_flutter.activity.MainActivity" on path: DexPathList[[zip file "/data/app/com.qiangxi.wx_assistant_flutter-HTuMLA_86hLW95aeKW4w3g==/base.apk"],nativeLibraryDirectories=[/data/app/com.qiangxi.wx_assistant_flutter-HTuMLA_86hLW95aeKW4w3g==/lib/arm64, /data/app/com.qiangxi.wx_assistant_flutter-HTuMLA_86hLW95aeKW4w3g==/base.apk!/lib/arm64-v8a, /system/lib64, /vendor/lib64]]
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:125)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
        at android.app.Instrumentation.newActivity(Instrumentation.java:1180)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2837)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3033) 
        at android.app.ActivityThread.-wrap11(Unknown Source:0) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1734) 
        at android.os.Handler.dispatchMessage(Handler.java:106) 
        at android.os.Looper.loop(Looper.java:192) 
        at android.app.ActivityThread.main(ActivityThread.java:6811) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:817) 


我查看了dex文件,却没有找到Activity类。 但是实际上有这种活动,

class MainActivity : FlutterActivity() {
    companion object {
        private val EXECUTOR_SERVICE = Executors.newSingleThreadExecutor()
    }

    override fun onCreate(savedInstanceState: Bundle) {
        super.onCreate(savedInstanceState)
        GeneratedPluginRegistrant.registerWith(this)

        MethodChannel(flutterView, CHANNEL_APK_INFO)
            .setMethodCallHandler { methodCall, result ->
                val method = methodCall.method
                when (method) {
                    METHOD_GET_APK_INFO -> {
                        EXECUTOR_SERVICE.submit {
                            val apks = ApkModel.obtainAndParseApk(applicationContext)
                            if (apks.isEmpty()) {
                                result.error("error", "no result.", null)
                            } else {
                                result.success(apks)
                            }
                        }
                    }
                }
            }
    }
}

和清单文件:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="com.qiangxi.wx.assistant.flutter">

    <!-- io.flutter.app.FlutterApplication is an android.app.Application that
         calls FlutterMain.startInitialization(this); in its onCreate method.
         In most cases you can leave this as-is, but you if you want to provide
         additional functionality it is fine to subclass or reimplement
         FlutterApplication and put your custom class here. -->
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.INTERNET"/>

    <application
        android:name="io.flutter.app.FlutterApplication"
        android:label="wx_assistant_flutter"
        android:icon="@mipmap/ic_launcher"
        tools:ignore="GoogleAppIndexingWarning">
        <activity
            android:name=".activity.MainActivity"
            android:launchMode="singleTop"
            android:theme="@style/LaunchTheme"
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
            android:hardwareAccelerated="true"
            android:windowSoftInputMode="adjustResize">
            <!-- This keeps the window background of the activity showing
                 until Flutter renders its first frame. It can be removed if
                 there is no splash screen (such as the default splash screen
                 defined in @style/LaunchTheme). -->
            <meta-data
                android:name="io.flutter.app.android.SplashScreenUntilFirstFrame"
                android:value="true" />
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
    </application>
</manifest>

和build.gradle:

def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
    localPropertiesFile.withReader('UTF-8') { reader ->
        localProperties.load(reader)
    }
}

def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
    throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
    flutterVersionCode = '1'
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
    flutterVersionName = '1.0'
}

apply plugin: 'com.android.application'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
    compileSdkVersion 28

    lintOptions {
        disable 'InvalidPackage'
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.qiangxi.wx.assistant.flutter"
        minSdkVersion 16
        targetSdkVersion 28
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            // TODO: Add your own signing config for the release build.
            // Signing with the debug keys for now, so `flutter run --release` works.
            signingConfig signingConfigs.debug
        }
    }
}

flutter {
    source '../..'
}

dependencies {
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

我已经检查了相关代码,没有发现任何问题,我不明白为什么dex文件中没有Activity类,请告诉我原因,谢谢!

the picture -> dex file has no Activity

1 个答案:

答案 0 :(得分:0)

我找到了原因,因为我手动将项目修改为kotlin语言,但没有添加kotlin相关的依赖项,导致kotlin相关的类未编译,因此生成的apk中没有kotlin相关的类。