cordova java.lang.RuntimeException:无法示例化路径上的应用程序android.hardware.bluetooth:DexPath列表

i7uaboj4  于 2022-11-15  发布在  Java
关注(0)|答案(1)|浏览(127)

我想使用Ionic 4来编译Android 12应用程序。
当我使用JDK 8 + SDK Level 27.0.3 for Android〈= 10编译我的ionic v4项目时,它工作正常。
但对于Android 12,我需要使用SDK级别31.0.0 + JDK 11 + Gradle 7。*并且会崩溃
更新后,当我打开我的应用程序,我看到启动屏幕半秒钟,然后它崩溃。
在我adb shell之后我得到

E AndroidRuntime: FATAL EXCEPTION: main
E AndroidRuntime: Process: com.myapp, PID: 28761
E AndroidRuntime: java.lang.RuntimeException: Unable to instantiate application android.hardware.bluetooth package com.myapp: java.lang.ClassNotFoundException: Didn't find class "android.hardware.bluetooth" on path: DexPathList[[zip file "/data/app/~~8T8KfSjt3r4E8wgw-yQ0KA==/com.myapp-3qG2CR3HTq76WQg0MM5V1Q==/base.apk"],nativeLibraryDirectories=[/data/app/~~8T8KfSjt3r4E8wgw-yQ0KA==/com.myapp-3qG2CR3HTq76WQg0MM5V1Q==/lib/arm64, /data/app/~~8T8KfSjt3r4E8wgw-yQ0KA==/com.myapp-3qG2CR3HTq76WQg0MM5V1Q==/base.apk!/lib/arm64-v8a, /system/lib64, /system/system_ext/lib64]]
E AndroidRuntime:   at android.app.LoadedApk.makeApplication(LoadedApk.java:1464)
E AndroidRuntime:   at android.app.ActivityThread.handleBindApplication(ActivityThread.java:7458)
E AndroidRuntime:   at android.app.ActivityThread.access$1700(ActivityThread.java:310)
E AndroidRuntime:   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2281)
E AndroidRuntime:   at android.os.Handler.dispatchMessage(Handler.java:106)
E AndroidRuntime:   at android.os.Looper.loopOnce(Looper.java:226)
E AndroidRuntime:   at android.os.Looper.loop(Looper.java:313)
E AndroidRuntime:   at android.app.ActivityThread.main(ActivityThread.java:8663)
E AndroidRuntime:   at java.lang.reflect.Method.invoke(Native Method)
E AndroidRuntime:   at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:567)
E AndroidRuntime:   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135)
E AndroidRuntime: Caused by: java.lang.ClassNotFoundException: Didn't find class "android.hardware.bluetooth" on path: DexPathList[[zip file "/data/app/~~8T8KfSjt3r4E8wgw-yQ0KA==/com.myapp-3qG2CR3HTq76WQg0MM5V1Q==/base.apk"],nativeLibraryDirectories=[/data/app/~~8T8KfSjt3r4E8wgw-yQ0KA==/com.myapp-3qG2CR3HTq76WQg0MM5V1Q==/lib/arm64, /data/app/~~8T8KfSjt3r4E8wgw-yQ0KA==/com.myapp-3qG2CR3HTq76WQg0MM5V1Q==/base.apk!/lib/arm64-v8a, /system/lib64, /system/system_ext/lib64]]
E AndroidRuntime:   at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:218)
E AndroidRuntime:   at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
E AndroidRuntime:   at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
E AndroidRuntime:   at android.app.AppComponentFactory.instantiateApplication(AppComponentFactory.java:76)
E AndroidRuntime:   at androidx.core.app.CoreComponentFactory.instantiateApplication(CoreComponentFactory.java:52)
E AndroidRuntime:   at android.app.Instrumentation.newApplication(Instrumentation.java:1177)
E AndroidRuntime:   at android.app.LoadedApk.makeApplication(LoadedApk.java:1456)
E AndroidRuntime:   ... 10 more

我在 * config.xml * 中使用

<?xml version='1.0' encoding='utf-8'?>
<widget id="com.myappid" version="4.4.49" xmlns="http://www.w3.org/ns/widgets" xmlns:android="http://schemas.android.com/apk/res/android">
    <name>My app Title</name>
    <description>Blablabla</description>
    <author email="sales@myapp.com" href="http://myapp.com/">MyApp</author>
    <content src="index.html" />
    <access origin="*" />
    <allow-navigation href="*" />
    <allow-intent href="http://*/*" />
    <allow-intent href="https://*/*" />
    <allow-intent href="ws://*/*" />
    <allow-intent href="tel:*" />
    <allow-intent href="sms:*" />
    <allow-intent href="mailto:*" />
    <allow-intent href="geo:*" />
    <preference name="ScrollEnabled" value="false" />
    <preference name="android-minSdkVersion" value="28" />
    <preference name="android-targetSdkVersion" value="31" />
    <preference name="BackupWebStorage" value="none" />
    <preference name="SplashMaintainAspectRatio" value="true" />
    <preference name="FadeSplashScreenDuration" value="300" />
    <preference name="SplashShowOnlyFirstTime" value="false" />
    <preference name="SplashScreen" value="screen" />
    <preference name="SplashScreenDelay" value="3000" />
    <preference name="loadUrlTimeoutValue" value="700000" />
    <platform name="android">
        <edit-config file="app/src/main/AndroidManifest.xml" mode="merge" target="/manifest/application">
            <application android:usesCleartextTraffic="true" />
            <application android:requestLegacyExternalStorage="true" />
            <activity android:exported="true" />
            <uses-permission android:name="android.permission.BLUETOOTH" />
            <uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
            <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
            <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
            <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
            <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
            <uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
            <uses-feature android:name="android.hardware.bluetooth" android:required="true" />
        </edit-config>
        <resource-file src="resources/android/xml/network_security_config.xml" target="app/src/main/res/xml/network_security_config.xml" />
        <preference name="SplashMaintainAspectRatio" value="true" />
        <preference name="SplashShowOnlyFirstTime" value="true" />
        <preference name="AndroidPersistentFileLocation" value="Compatibility" />
        <preference name="loadUrlTimeoutValue" value="700000" />
        <icon density="ldpi" src="resources/android/icon/drawable-ldpi-icon.png" />
        <icon density="mdpi" src="resources/android/icon/drawable-mdpi-icon.png" />
        <icon density="hdpi" src="resources/android/icon/drawable-hdpi-icon.png" />
        <icon density="xhdpi" src="resources/android/icon/drawable-xhdpi-icon.png" />
        <icon density="xxhdpi" src="resources/android/icon/drawable-xxhdpi-icon.png" />
        <icon density="xxxhdpi" src="resources/android/icon/drawable-xxxhdpi-icon.png" />
    </platform>

它会转换成我的 * AndroidManifest.xml *

<?xml version='1.0' encoding='utf-8'?>
<manifest android:hardwareAccelerated="true" android:versionCode="40449" android:versionName="4.4.49" package="com.myapp" xmlns:android="http://schemas.android.com/apk/res/android">
    <supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:resizeable="true" android:smallScreens="true" android:xlargeScreens="true" />
    <uses-permission android:name="android.permission.INTERNET" />
    <application android:exported="true" android:hardwareAccelerated="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:name="android.hardware.bluetooth" android:requestLegacyExternalStorage="true" android:required="true" android:supportsRtl="true" android:usesCleartextTraffic="true">
        <activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|smallestScreenSize|screenLayout|uiMode" android:exported="true" android:label="@string/activity_name" android:launchMode="singleTop" android:name="MainActivity" android:theme="@style/Theme.AppCompat.NoActionBar" android:windowSoftInputMode="adjustResize">
            <intent-filter android:label="@string/launcher_name">
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <provider android:authorities="${applicationId}.cordova.plugin.camera.provider" android:exported="false" android:grantUriPermissions="true" android:name="org.apache.cordova.camera.FileProvider">
            <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/camera_provider_paths" />
        </provider>
        <activity android:clearTaskOnLaunch="true" android:configChanges="orientation|keyboardHidden|screenSize" android:exported="false" android:name="com.google.zxing.client.android.CaptureActivity" android:theme="@android:style/Theme.NoTitleBar.Fullscreen" android:windowSoftInputMode="stateAlwaysHidden" />
        <activity android:label="Share" android:name="com.google.zxing.client.android.encode.EncodeActivity" />
    </application>
    <uses-permission android:name="android.permission.BLUETOOTH" />
    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <queries>
        <intent>
            <action android:name="android.media.action.IMAGE_CAPTURE" />
        </intent>
        <intent>
            <action android:name="android.intent.action.GET_CONTENT" />
        </intent>
        <intent>
            <action android:name="android.intent.action.PICK" />
        </intent>
        <intent>
            <action android:name="com.android.camera.action.CROP" />
            <data android:mimeType="image/*" android:scheme="content" />
        </intent>
    </queries>
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.FLASHLIGHT" />
    <uses-feature android:name="android.hardware.camera" android:required="true" />
</manifest>

正如你所看到的,我认为我有所有正确的蓝牙权限,但为什么在地球上它崩溃的Android 12!?

wkftcu5l

wkftcu5l1#

好吧,经过3天的废话,我终于明白了问题所在。
根据这一点:https://developer.android.com/studio/build/multidex.html
您需要为您的项目安装/启用Multidex,因为如果它在启动时使用默认情况下未加载的类,它将崩溃并显示以下错误:

java.lang.RuntimeException: Unable to instantiate application "blablabla"  on path: DexPathList

要在离子上修复此问题:

cordova plugin add cordova-plugin-enable-multidex

config.xml 中添加androidx.multidex. MultiDex应用程序

<platform name="android">
        <edit-config file="app/src/main/AndroidManifest.xml" mode="merge" target="/manifest/application">
            ...
            <application android:name="androidx.multidex.MultiDexApplication" />
            ...

然后

ionic cordova platform remove android
ionic cordova platform add android

相关问题