在运行时为android dex错误构建新的app-bundle

时间:2018-06-04 15:28:10

标签: android android-app-bundle

我按照https://developer.android.com/guide/app-bundle/build的说明构建了新的Android应用包 - 但是我从Play商店安装时遇到错误。

2018-06-04 11:06:09.397 10595-10595/? E/AndroidRuntime: Caused by: java.lang.RuntimeException: java.lang.ClassNotFoundException: io.org.app.ui.loading.LoadingFragment
    at androidx.navigation.fragment.b$a.a(FragmentNavigator.java:219)
    at androidx.navigation.fragment.b$a.a(FragmentNavigator.java:202)
    at androidx.navigation.k.a(NavInflater.java:140)
    at androidx.navigation.k.a(NavInflater.java:169)
    at androidx.navigation.k.a(NavInflater.java:120)
        ... 36 more
 Caused by: java.lang.ClassNotFoundException: io.org.app.ui.loading.LoadingFragment
    at java.lang.Class.classForName(Native Method)
    at java.lang.Class.forName(Class.java:453)
    at androidx.navigation.fragment.b$a.a(FragmentNavigator.java:215)
        ... 40 more
 Caused by: java.lang.ClassNotFoundException: Didn't find class "io.org.app.ui.loading.LoadingFragment" on path: DexPathList[[zip file "/system/framework/org.apache.http.legacy.boot.jar", zip file "/data/app/io.org.app-2KUWPMF_QJ31_iG8kGu1rA==/base.apk", zip file "/data/app/io.org.app-2KUWPMF_QJ31_iG8kGu1rA==/split_config.arm64_v8a.apk", zip file "/data/app/io.org.app-2KUWPMF_QJ31_iG8kGu1rA==/split_config.en.apk", zip file "/data/app/io.prg.app-2KUWPMF_QJ31_iG8kGu1rA==/split_config.iw.apk", zip file "/data/app/io.org.app-2KUWPMF_QJ31_iG8kGu1rA==/split_config.xxhdpi.apk"],nativeLibraryDirectories=[/data/app/io.org.app-2KUWPMF_QJ31_iG8kGu1rA==/lib/arm64, /data/app/io.org.app-2KUWPMF_QJ31_iG8kGu1rA==/base.apk!/lib/arm64-v8a, /data/app/io.org.app-2KUWPMF_QJ31_iG8kGu1rA==/split_config.arm64_v8a.apk!/lib/arm64-v8a, /data/app/io.org.app-2KUWPMF_QJ31_iG8kGu1rA==/split_config.en.apk!/lib/arm64-v8a, /data/app/io.org.app-2KUWPMF_QJ31_iG8kGu1rA==/split_config.iw.apk!/lib/arm64-v8a, /data/app/io.org.app-2KUWPMF_QJ31_iG8kGu1rA==/split_config.xxhdpi.apk!/lib/arm64-v8a, /system/lib64, /vendor/lib64]]
    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:125)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
        ... 43 more
    Suppressed: java.io.IOException: No original dex files found for dex location /data/app/io.org.app-2KUWPMF_QJ31_iG8kGu1rA==/split_config.arm64_v8a.apk
    at dalvik.system.DexFile.openDexFileNative(Native Method)
    at dalvik.system.DexFile.openDexFile(DexFile.java:354)
    at dalvik.system.DexFile.<init>(DexFile.java:101)
    at dalvik.system.DexFile.<init>(DexFile.java:75)
    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.ClassLoaderFactory.createClassLoader(ClassLoaderFactory.java:73)
    at com.android.internal.os.ClassLoaderFactory.createClassLoader(ClassLoaderFactory.java:88)
    at android.app.ApplicationLoaders.getClassLoader(ApplicationLoaders.java:72)
    at android.app.ApplicationLoaders.getClassLoader(ApplicationLoaders.java:38)
    at android.app.LoadedApk.createOrUpdateClassLoaderLocked(LoadedApk.java:715)
    at android.app.LoadedApk.getClassLoader(LoadedApk.java:750)
    at android.app.LoadedApk.getResources(LoadedApk.java:972)
    at android.app.ContextImpl.createAppContext(ContextImpl.java:2329)
    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5743)
    at android.app.ActivityThread.access$1000(ActivityThread.java:198)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1637)
            ... 6 more
    Suppressed: java.io.IOException: No original dex files found for dex location /data/app/io.org.app-2KUWPMF_QJ31_iG8kGu1rA==/split_config.en.apk
    at dalvik.system.DexFile.openDexFileNative(Native Method)
    at dalvik.system.DexFile.openDexFile(DexFile.java:354)
    at dalvik.system.DexFile.<init>(DexFile.java:101)
    at dalvik.system.DexFile.<init>(DexFile.java:75)
    at dalvik.system.DexPathList.loadDexFile(DexPathList.java:374)

我在构建中包含了以下内容:

android {
    buildTypes {
        release {
            multiDexKeepProguard file ('multidex-keep.pro')
        }
    }
}

multidex-keep.pro:

-keep class io.org.app.ui.main.** { *; }
-keep class io.org.app.ui.loading.** { *; }

4 个答案:

答案 0 :(得分:2)

看起来类io.org.app.ui.loading.LoadingFragment是通过反射加载的,但是你的proguard文件不会阻止该类被混淆,所以它已被重命名,这解释了为什么找不到它。

我想你在本地部署应用程序的发布版本时会遇到同样的错误。

尝试调整proguard文件以防止重命名该类。

答案 1 :(得分:1)

我有同样的问题。 检查是否添加:

apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'

在您的 build.gradle 文件中。

答案 2 :(得分:0)

下面我列出了可能的解决方案, 一步一步尝试此步骤:

  • 1删除设备上的应用并清理项目

  • 2在调试模式下禁用 minifyEnabled

转到调试块中的build.gradle(Module:app)并禁用minifyEnabled:

buildTypes {

    debug {
        minifyEnabled false

     }
}
  • 3在应用程序的gradle文件中将dataBinding设置为true

就我而言,我包括另一种布局 <include layout="@layout/attached_layout" /> 到我活动的布局,就解决了。

    android {
    ...
    ...
    ...

    dataBinding {
        enabled = true
    }

    }
  • 4检查清单中活动的相对路径

例如:

<activity android:name="com.myExactPackageName.MyActivity"
  • 5在自定义视图中检查软件包名称

    <com.myExactPackageName.MyCustomView
        android:id="@+id/myview"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="16dp"
        android:layout_marginRight="16dp" />
    
  • 6尝试在应用程序build.gradle中禁用预删除:

    dexOptions {
     preDexLibraries false
    }
    
  • 7禁用即时运行

    转到文件->设置->构建,执行,部署->即时运行->取消选中即时运行复选框

  • 8尝试MultiDexApplication

这在build.gradle(Module:app)

android { 

defaultConfig {
      ...
      multiDexEnabled true
}

dependencies {
     ... 
    implementation 'androidx.multidex:multidex:2.0.1'
}


}

如果您使用的是应用程序类,则必须使用MultiDexApplication而不是Application进行扩展,并将其添加到 AndroidManifest.xml

中的应用程序标记中
<application
    android:name="com.myPackageName.MyApplication"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name">

否则从库中添加MultiDexApplication类路径作为名称

<application
    android:name="androidx.multidex.MultiDexApplication"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name">

答案 3 :(得分:0)

解决了。以上都不是。导致它是editorOptions错误。

  compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}