У меня есть проект Android Studio, который я тестировал на API 30 и работает нормально. Теперь я попытался запустить его на API 26 (это минимальная версия SDK, которую я установил для проекта), и мне не удалось запустить приложение. Оба раза я использовал эмулированный Pixel 3a и одно внешнее устройство.
Журнал ошибок:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.main.xyz, PID: 9389
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.main.xyz/com.main.xyz.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "com.main.xyz.MainActivity" on path: DexPathList[[zip file "/data/app/com.main.xyz-rZkYLBaLo3gdkb7oCChonQ==/base.apk"],nativeLibraryDirectories=[/data/app/com.main.xyz-rZkYLBaLo3gdkb7oCChonQ==/lib/x86, /system/lib, /vendor/lib]]
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2718)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.main.xyz.MainActivity" on path: DexPathList[[zip file "/data/app/com.main.xyz-rZkYLBaLo3gdkb7oCChonQ==/base.apk"],nativeLibraryDirectories=[/data/app/com.main.xyz-rZkYLBaLo3gdkb7oCChonQ==/lib/x86, /system/lib, /vendor/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:93)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at android.app.Instrumentation.newActivity(Instrumentation.java:1173)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2708)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
Suppressed: java.io.IOException: Failed to open dex files from /data/app/com.main.xyz-rZkYLBaLo3gdkb7oCChonQ==/base.apk because: Failure to verify dex file '/data/app/com.main.xyz-rZkYLBaLo3gdkb7oCChonQ==/base.apk': Bad method handle type 7
at dalvik.system.DexFile.openDexFileNative(Native Method)
at dalvik.system.DexFile.openDexFile(DexFile.java:353)
at dalvik.system.DexFile.<init>(DexFile.java:100)
at dalvik.system.DexFile.<init>(DexFile.java:74)
at dalvik.system.DexPathList.loadDexFile(DexPathList.java:374)
at dalvik.system.DexPathList.makeDexElements(DexPathList.java:337)
at dalvik.system.DexPathList.<init>(DexPathList.java:157)
at dalvik.system.BaseDexClassLoader.<init>(BaseDexClassLoader.java:65)
at dalvik.system.PathClassLoader.<init>(PathClassLoader.java:64)
at com.android.internal.os.PathClassLoaderFactory.createClassLoader(PathClassLoaderFactory.java:43)
at android.app.ApplicationLoaders.getClassLoader(ApplicationLoaders.java:69)
at android.app.ApplicationLoaders.getClassLoader(ApplicationLoaders.java:36)
at android.app.LoadedApk.createOrUpdateClassLoaderLocked(LoadedApk.java:676)
at android.app.LoadedApk.getClassLoader(LoadedApk.java:709)
at android.app.LoadedApk.getResources(LoadedApk.java:936)
at android.app.ContextImpl.createAppContext(ContextImpl.java:2242)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5672)
at android.app.ActivityThread.-wrap1(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1661)
... 6 more
My MainActivity. java:
public class MainActivity extends AppCompatActivity {
private static final String TAG = "MainActivity";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
}
//Called by Button
public void login(View v) {
Intent intent = new Intent(MainActivity.this, Uebersicht.class);
startActivity(intent)
}
My build.gradle (приложение):
apply plugin: 'com.android.application'
android {
compileSdkVersion 30
buildToolsVersion "30.0.0"
defaultConfig {
applicationId "com.main.xyz"
minSdkVersion 26
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
proguardFiles 'proguard-rules.pro'
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.android.material:material:1.1.0'
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
implementation 'com.google.android.gms:play-services-vision:20.1.0'
}
Моя сборка .grade (проект):
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:4.0.0"
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
И мой манифест. xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.main.xyz">
<uses-permission android:name="android.permission.CAMERA" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme"
android:usesCleartextTraffic="true">
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Uebersicht"
android:label="" />
<activity
android:name=".ProductActivity"
android:label="" />
<activity
android:name=".AddActivity"
android:label=""/>
<activity
android:name=".ScanActivity"
android:label="" />
</application>
</manifest>
Давно искал решение. Поскольку я новичок в Android, я очень благодарен за помощь. Если вы можете предоставить это, я действительно получил бы объяснение моей проблемы, а также решение, чтобы понять, что здесь не так.