我在动态功能模块中使用了一些库。这些库正在为清单添加一些提供程序。
例如,在动态模块的build.gradle文件中:
dependencies {
...
implementation 'com.github.esafirm.android-image-picker:imagepicker:1.11.1'
...
}
该库将以下标记添加到清单中:
<provider
android:name="com.esafirm.imagepicker.helper.ImagePickerFileProvider"
android:authorities="{$applicationId}.imagepicker.provider"
android:exported="false"
android:grantUriPermissions="true" >
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/image_picker_provider_paths" />
</provider>
问题是当我构建基本模块时,应用程序崩溃,因为它找不到提供程序。我该怎么解决?
如here所述:
您应用的基本模块的清单与其他任何应用模块的清单相似。请记住,当Google Play生成您应用的基本APK时,它将所有模块的清单合并到基本APK的清单中。
但是为什么只有提供者会受到影响?活动会被忽略吗?
这是我得到的堆栈跟踪:
java.lang.RuntimeException: Unable to get provider com.esafirm.imagepicker.helper.ImagePickerFileProvider: java.lang.ClassNotFoundException: Didn't find class "com.esafirm.imagepicker.helper.ImagePickerFileProvider" on path: DexPathList[[zip file "/data/app/ir.rashin.mototel-h7B8g42gBcVABkik16vqzw==/base.apk"],nativeLibraryDirectories=[/data/app/ir.rashin.mototel-h7B8g42gBcVABkik16vqzw==/lib/x86, /system/lib]]
at android.app.ActivityThread.installProvider(ActivityThread.java:6396)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:5938)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5853)
at android.app.ActivityThread.access$1100(ActivityThread.java:199)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1650)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.esafirm.imagepicker.helper.ImagePickerFileProvider" on path: DexPathList[[zip file "/data/app/ir.rashin.mototel-h7B8g42gBcVABkik16vqzw==/base.apk"],nativeLibraryDirectories=[/data/app/ir.rashin.mototel-h7B8g42gBcVABkik16vqzw==/lib/x86, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at android.app.AppComponentFactory.instantiateProvider(AppComponentFactory.java:121)
at android.support.v4.app.CoreComponentFactory.instantiateProvider(CoreComponentFactory.java:62)
at android.app.ActivityThread.installProvider(ActivityThread.java:6380)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:5938)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5853)
at android.app.ActivityThread.access$1100(ActivityThread.java:199)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1650)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
答案 0 :(得分:-1)
尝试此解决方案。
在您的应用程序build.gradle中添加带有tools:node="remove"
的提供程序
<provider
android:name="com.esafirm.imagepicker.helper.ImagePickerFileProvider"
android:authorities="{$applicationId}.imagepicker.provider"
android:exported="false"
android:grantUriPermissions="true"
tools:node="remove" >
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/image_picker_provider_paths" />
</provider>
在Android Studio中,它将标记为红色,但是当您使用进行构建时
./gradlew clean bundleRelease
它应该成功完成。
现在,您可以生成.apks文件并将其解压缩:
java -jar bundletool-all-0.10.2.jar build-apks --bundle=app.aab --output=release.apks --ks=release.keystore --ks-pass=pass:xxxxxx --ks-key-alias=xxxxxxkey --key-pass=pass:xxxxxx
unzip release.apks
此后,您可以解码.apk文件(例如,使用apktool)以查看它们的清单。 现在,在base-master.apk中,您应该看不到提供程序条目,而在{dynamic-module} master.apk中,它应该可用。
java -jar apktool_2.4.0.jar d release/splits/base-master.apk