我最近升级了 Android Studio 并添加了对 API 级别 27 的支持。为 API 27(像素 xl)创建了一个模拟器。
该应用程序在 Nexus 5X 模拟器上运行良好,但在 Pixel XL 模拟器上出现以下错误而失败。有人可以指导我正确的方向吗?\
错误:
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.localhost.myapp/com.mycompany.myapp.activity.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "com.mycompany.myapp.activity.MainActivity" on path: DexPathList[[zip file "/data/app/com.localhost.myapp-fwgWxCeG6fwAPqPFcI0DsA==/base.apk", zip file "/data/app/com.localhost.myapp-fwgWxCeG6fwAPqPFcI0DsA==/split_lib_directories_apk.apk", zip file "/data/app/com.localhost.myapp-fwgWxCeG6fwAPqPFcI0DsA==/split_lib_resources_apk.apk"],nativeLibraryDirectories=[/data/app/com.localhost.myapp-fwgWxCeG6fwAPqPFcI0DsA==/lib/x86, /system/lib, /vendor/lib]]
摇篮文件:
apply plugin: 'com.android.application'
apply plugin: 'org.greenrobot.greendao'
apply plugin: 'io.fabric'
android {
compileSdkVersion 27
buildToolsVersion '27.0.3'
defaultConfig {
applicationId 'com.localhost.myapp'
minSdkVersion 21
targetSdkVersion 27
versionCode 5
versionName "1.0.3"
}
buildTypes {
debug {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
packagingOptions {
exclude 'META-INF/ASL2.0'
exclude 'META-INF/LICENSE'
exclude 'META-INF/license.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/notice.txt'
}
productFlavors {
localhost {
}
}
applicationVariants.all { variant ->
if (variant.getBuildType().getName() == 'release') {
variant.assemble.doLast {
copy {
from variant.mappingFile
into "proguard"
rename { String fileName ->
"mapping-${variant.name}.txt"
}
}
}
}
}
}
def flavors = []
new File("app/flavors").eachFile() { file ->
def fileName = file.getName()
if (fileName.endsWith('.gradle')) {
flavors.push(fileName)
}
}
flavors.each { flavorName ->
apply from: rootProject.file("app/flavors/$flavorName")
}
greendao {
schemaVersion 1
targetGenDir "src/main/java"
daoPackage "com.mycompany.myapp.dao"
}
dependencies {
ext {
supportLibVersion = '27.1.0'
}
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation project(':aFileChooser')
implementation "com.android.support:support-compat:${supportLibVersion}"
implementation "com.android.support:appcompat-v7:${supportLibVersion}"
implementation "com.android.support:support-v4:${supportLibVersion}"
implementation "com.android.support:cardview-v7:${supportLibVersion}"
implementation "com.android.support:recyclerview-v7:${supportLibVersion}"
implementation "com.android.support:design:${supportLibVersion}"
implementation 'com.google.firebase:firebase-core:16.0.0'
implementation 'com.google.firebase:firebase-messaging:17.0.0'
implementation 'com.google.firebase:firebase-crash:16.0.0'
implementation 'com.crashlytics.sdk.android:crashlytics:2.9.3'
implementation 'com.google.android:flexbox:0.2.6'
implementation 'com.squareup.okhttp3:logging-interceptor:3.10.0'
implementation 'com.squareup.retrofit2:retrofit:2.4.0'
implementation 'com.squareup.retrofit2:converter-gson:2.4.0'
implementation 'com.squareup.picasso:picasso:2.71828'
implementation 'jp.wasabeef:richeditor-android:1.2.2'
implementation 'org.greenrobot:greendao:3.2.2'
implementation 'org.sufficientlysecure:html-textview:3.1'
testImplementation 'junit:junit:4.12'
}
repositories {
mavenCentral()
}
apply plugin: 'com.google.gms.google-services'
我试过multiDexEnabled true了,但这并没有解决问题。