Не удалось найти класс "com.example.android.App" по пути: DexPathList на Android 4 - PullRequest
0 голосов
/ 24 декабря 2018

У меня есть приложение Kotlin MultiDex, использующее Dagger 2 для DI.Все почти нормально, но у меня есть устройство с API 17 (Android 4.2.2), и иногда приложение вылетает сразу после запуска, за исключением

java.lang.RuntimeException: Невозможно создать экземпляр приложения com.example.android.App: java.lang.ClassNotFoundException: не найден класс "com.example.android.App" по пути: DexPathList [[zip-файл "/data/app/com.example.android-1.apk"],nativeLibraryDirectories = [/ data / app-lib / com.example.android-1, / vendor / lib, / system / lib]]

Как правило, это происходит после Build -> Project и послеFile -> Invalidate caches / Restart, но не всегда.Обычно проект Rebuild помогает, но я хотел бы полностью исправить эти ситуации.

Скажите, пожалуйста, в чем может быть проблема?

Мой build.gradle (не полный):

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'io.fabric'
apply plugin: 'io.sentry.android.gradle'
apply plugin: 'kotlin-kapt'

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "com.example.android"
        minSdkVersion 16
        targetSdkVersion 27
        versionCode 58
        versionName "1.0"
        vectorDrawables.useSupportLibrary = true
        multiDexEnabled true
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    applicationVariants.all { variant ->
        variant.outputs.all { output ->
            outputFileName = "example.apk"
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])

    //Kotlin
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.11"

    // Coroutines
    implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.1.0"
    implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.1.0"
...

    // LiveData + ViewModel
    implementation "android.arch.lifecycle:extensions:1.1.1"

    implementation "com.android.support:multidex:1.0.3"
    implementation "com.android.support.constraint:constraint-layout:1.1.3"
...
     // Dagger
    implementation "com.google.dagger:dagger:2.19"
    implementation "com.google.dagger:dagger-android-support:2.19"
    kapt "com.google.dagger:dagger-compiler:2.19"
    kapt "com.google.dagger:dagger-android-processor:2.19"
...
}

Мой AndroidManifest.xml (не полный):

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="com.example.android">

    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

    <application
        android:name=".App"
        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"
        tools:ignore="AllowBackup,GoogleAppIndexingWarning">
        <activity
            android:name=".activities.SplashActivity"
            android:screenOrientation="portrait"
            android:theme="@style/Theme.Splash">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
...
    </application>
</manifest>

Мой класс приложения (App.kt, не полный)

class App: DaggerApplication() {

    override fun onCreate() {
        super.onCreate()
    ...
    }

    override fun attachBaseContext(base: Context?) {
        super.attachBaseContext(base)
        MultiDex.install(this)
    }

    override fun applicationInjector(): AndroidInjector<out DaggerApplication> =
        DaggerAppComponent.builder().application(this).build()

    }
}
...