0

我最近升级了 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了,但这并没有解决问题。

4

1 回答 1

0

经过大量调查,我发现“即时运行”功能导致了这个问题。如果我从 Android Studio 设置中禁用 Instant Run,则该应用程序将与所有源类一起部署。

副作用是调试器无法检测到类,我无法通过放置调试点进行调试。如果有人有任何其他解决方案,我很高兴看到这一点。

于 2018-06-10T12:12:12.010 回答