我尝试在 Android Studio 3.2.1 上创建一个新项目。在项目创建向导中,选择最低SDK版本支持作为 API级别21(Android 5.0),使用“ 清空活动”模板创建了一个项目。
在有和没有“ Kotlin”支持的情况下,我都尝试了相同的结果。当我尝试在任何模拟器/电话上运行此新创建的应用程序时,该应用程序崩溃了。
但是,当我将minSDK更改为小于21时,该应用程序成功运行。当minSDK版本高于21时,它也运行良好。
注意:compileSDKVersion和targetSDKVersion设置为28
这是崩溃日志。
2018-11-10 02:25:43.886 3742-3742/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.kbeanie.test1, PID: 3742
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.kbeanie.test1/com.kbeanie.test1.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "com.kbeanie.test1.MainActivity" on path: DexPathList[[zip file "/data/app/com.kbeanie.test1-BOVWTjJJqRM5jnzV5X3nnw==/base.apk"],nativeLibraryDirectories=[/data/app/com.kbeanie.test1-BOVWTjJJqRM5jnzV5X3nnw==/lib/x86, /system/lib, /vendor/lib]]
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2679)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
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:807)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.kbeanie.test1.MainActivity" on path: DexPathList[[zip file "/data/app/com.kbeanie.test1-BOVWTjJJqRM5jnzV5X3nnw==/base.apk"],nativeLibraryDirectories=[/data/app/com.kbeanie.test1-BOVWTjJJqRM5jnzV5X3nnw==/lib/x86, /system/lib, /vendor/lib]]
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:1174)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2669)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
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:807)
Suppressed: java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v7/app/AppCompatActivity;
at java.lang.VMClassLoader.findLoadedClass(Native Method)
at java.lang.ClassLoader.findLoadedClass(ClassLoader.java:738)
at java.lang.ClassLoader.loadClass(ClassLoader.java:363)
... 12 more
Caused by: java.lang.ClassNotFoundException: android.support.v7.app.AppCompatActivity
at java.lang.VMClassLoader.findLoadedClass(Native Method)
at java.lang.ClassLoader.findLoadedClass(ClassLoader.java:738)
at java.lang.ClassLoader.loadClass(ClassLoader.java:363)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
... 15 more
Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v4/app/FragmentActivity;
... 15 more
Caused by: java.lang.ClassNotFoundException: android.support.v4.app.FragmentActivity
at java.lang.VMClassLoader.findLoadedClass(Native Method)
at java.lang.ClassLoader.findLoadedClass(ClassLoader.java:738)
at java.lang.ClassLoader.loadClass(ClassLoader.java:363)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
... 15 more
Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v4/app/SupportActivity;
... 15 more
Caused by: java.lang.ClassNotFoundException: android.support.v4.app.SupportActivity
at java.lang.VMClassLoader.findLoadedClass(Native Method)
at java.lang.ClassLoader.findLoadedClass(ClassLoader.java:738)
at java.lang.ClassLoader.loadClass(ClassLoader.java:363)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
... 15 more
Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Landroid/arch/lifecycle/LifecycleOwner;
... 15 more
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.arch.lifecycle.LifecycleOwner" on path: DexPathList[[zip file "/data/app/com.kbeanie.test1-BOVWTjJJqRM5jnzV5X3nnw==/base.apk"],nativeLibraryDirectories=[/data/app/com.kbeanie.test1-BOVWTjJJqRM5jnzV5X3nnw==/lib/x86, /system/lib, /vendor/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:125)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
... 15 more
这是build.gradle文件的内容。
apply plugin: 'com.android.application' android { compileSdkVersion 28 defaultConfig { applicationId "com.kbeanie.test2" minSdkVersion 15 targetSdkVersion 28 versionCode 1 versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } } dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation 'com.android.support:appcompat-v7:28.0.0' implementation 'com.android.support.constraint:constraint-layout:1.1.3' 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' }