1

我正在按照https://developer.android.com/guide/app-bundle/build上的说明构建新的 android app-bundle,但是从 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

4 回答 4

2

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

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

在您的build.gradle文件中。

于 2018-09-21T13:56:12.890 回答
2

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

我想当您在本地部署应用程序的发布版本时应该会遇到相同的错误。

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

于 2018-06-04T15:47:31.370 回答
1

解决了。以上都不起作用。原因是 compilerOptions 错误。

  compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}
于 2020-01-06T09:34:27.193 回答
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 尝试在 app build.gradle 中禁用 pre-dexing:

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

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

  • 8 尝试 MultiDexApplication

这在 build.gradle(Module:app)

android { 

defaultConfig {
      ...
      multiDexEnabled true
}

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


}

如果您使用的是应用程序类,则必须使用它来扩展它,MultiDexApplication而不是将其添加到AndroidManifest.xmlApplication中的应用程序标记中

<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">
于 2019-02-04T03:10:56.747 回答