的gradle:
classpath 'com.android.tools.build:gradle:3.0.1'
我做了:
禁用即时运行
构建 - >清理项目
构建 - >构建APK(s)
adb install app-debug.apk
启动申请
日志错误:
FATAL EXCEPTION: main
Process: com.example, PID: 23753
java.lang.RuntimeException: Unable to instantiate application com.example.TheApplication: java.lang.ClassNotFoundException: Didn't find class "com.example.TheApplication" on path: DexPathList[[zip file "/data/app/com.example-1/base.apk"],nativeLibraryDirectories=[/data/app/com.example-1/lib/arm, /data/app/com.example-1/base.apk!/lib/armeabi-v7a, /vendor/lib, /system/lib]]
at android.app.LoadedApk.makeApplication(LoadedApk.java:676)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6289)
at android.app.ActivityThread.access$1800(ActivityThread.java:221)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1860)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7224)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.TheApplication" on path: DexPathList[[zip file "/data/app/com.example-1/base.apk"],nativeLibraryDirectories=[/data/app/com.example-1/lib/arm, /data/app/com.example-1/base.apk!/lib/armeabi-v7a, /vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
at android.app.Instrumentation.newApplication(Instrumentation.java:1004)
at android.app.LoadedApk.makeApplication(LoadedApk.java:666)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6289)
at android.app.ActivityThread.access$1800(ActivityThread.java:221)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1860)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7224)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Suppressed: java.lang.ClassNotFoundException: com.example.TheApplication
at java.lang.Class.classForName(Native Method)
at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
... 12 more
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available
答案 0 :(得分:0)
转到文件 - >设置 - >实例运行的未选中即时运行复选框 - >按应用 删除构建文件夹,清理并重建项目
此后我的问题得到解决
答案 1 :(得分:0)
当我遇到类似的错误时,我发现我的遗失类是在另一个dex文件中。
我简单地添加了multidex-config.pro文件(将“com.sample.package”替换为你的包)
-keep class com.sample.package.** { *; }
并在我的build.gradle中添加了multiDexKeepProguard
buildTypes {
debug {
multiDexKeepProguard(new File("multidex-config.pro"))
applicationIdSuffix ".debug"
versionNameSuffix "-debug"
}
release {
multiDexKeepProguard(new File("multidex-config.pro"))
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
}
}
当gradle构建apk文件时,它会将类封装在一个dex文件中
希望有所帮助