简体   繁体   English

在Android项目中添加API 27支持会产生错误

[英]Adding API 27 support in Android project producing error

I recently upgraded Android studio and added support for API level 27. Created an emulator for API 27 (pixel xl). 我最近升级了Android Studio,并添加了对API级别27的支持。为API 27(像素xl)创建了一个模拟器。

The app runs perfectly fine on Nexus 5X emulator, but fails with following error on Pixel XL emulator. 该应用在Nexus 5X模拟器上可以完美运行,但在Pixel XL模拟器上失败并出现以下错误。 Can someone guide me with right direction?\\ 有人可以指导我正确的方向吗?\\

Error: 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]] 错误: 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]]

Gradle file: 摇篮文件:

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'

I tried multiDexEnabled true but that did not solve the problem. 我尝试将multiDexEnabled true但这并不能解决问题。

After a lot of investigation, I found the "Instant Run" feature is causing the issue. 经过大量调查,我发现引起问题的原因是“即时运行”功能。 If I disable Instant Run from Android Studio settings, the app is deployed with all source classes. 如果我从Android Studio设置中禁用“即时运行”,则该应用程序将与所有源类一起部署。

The side effect is the debugger cannot detect the classes and I cannot debug by placing debug points. 副作用是调试器无法检测到类,并且无法通过放置调试点进行调试。 If someone has any other solution, I am glad to see that. 如果有人有其他解决方案,我很高兴看到。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM