簡體   English   中英

API 14上的Multidex問題-具有targetSdkVersion 27的API 19(Android 4.X)

[英]Multidex problem on API 14 - API 19 (Android 4.X) with targetSdkVersion 27

我用過

compileSdkVersion 23
buildToolsVersion "23.0.3"

defaultConfig {
    minSdkVersion 14
    targetSdkVersion 23
    ...
    multiDexEnabled true
}

dependencies {
    compile 'com.android.support:multidex:1.0.1'
    ...
}

app級別的build.gradle

<manifest package="com.example"
...
    <application
        android:name=".AppContext"
        ...
    >
>

由於我的應用程序manifest使用了很長時間,因此肯定引用了超過64K的方法 現在,我將其更改為Android Studio 3.3.2下的全新SDK和multidex lib。

compileSdkVersion 27
buildToolsVersion "27.0.3"


defaultConfig {
    minSdkVersion 14
    targetSdkVersion 27
    ...
    multiDexEnabled true
}

dependencies {
    compile 'com.android.support:multidex:1.0.3'
    ...
}

和應用程序在所有可用的Android 4.X設備上安裝時開始崩潰。 大多數崩潰具有如下的stacktrace:

java.lang.RuntimeException:
at android.app.ActivityThread.installProvider (ActivityThread.java:5236)
at android.app.ActivityThread.installContentProviders (ActivityThread.java:4828)
at android.app.ActivityThread.handleBindApplication (ActivityThread.java:4711)
at android.app.ActivityThread.access$1600 (ActivityThread.java:175)
at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1368)
at android.os.Handler.dispatchMessage (Handler.java:102)
at android.os.Looper.loop (Looper.java:146)
at android.app.ActivityThread.main (ActivityThread.java:5602)
at java.lang.reflect.Method.invokeNative (Native Method)
at java.lang.reflect.Method.invoke (Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:1283)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1099)
at dalvik.system.NativeStart.main (Native Method)
Caused by: java.lang.ClassNotFoundException:
at dalvik.system.BaseDexClassLoader.findClass (BaseDexClassLoader.java:67)
at java.lang.ClassLoader.loadClass (ClassLoader.java:497)
at java.lang.ClassLoader.loadClass (ClassLoader.java:457)
at android.app.ActivityThread.installProvider (ActivityThread.java:5221)

我發現解決問題的唯一方法是排除

//    compile 'com.android.support:multidex:1.0.3'

app級別的build.gradle和更改

public class AppContext extends Application {
...}

public class AppContext extends MultiDexApplication {
...}

這是build tools 27.xx的錯誤還是什么!?

你可以這樣嘗試

1)移除

multiDexEnabled是

從應用程序gradle,僅添加

實現'com.android.support:multidex:1.0.3'

對您的應用程序依賴性

像這樣

apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
android {
compileSdkVersion 27
defaultConfig {
    applicationId "com.heizolscout.itclanbd.heizolscout"
    minSdkVersion 18
    targetSdkVersion 27
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard- 
rules.pro'
    }
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:multidex:1.0.3'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
implementation 'com.android.support:support-v4:27.1.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

我的一個應用程序中存在相同的問題。 使用像這樣擴展MultiDexApplication應用程序:

public class AppContext extends MultiDexApplication {

  ...

}

並使用如下所示的multidex依賴項:

compile 'com.android.support:multidex:1.0.3'

沒有用

我通過在Application類中使用MultiDex.install來解決它。 像這樣:

import android.support.multidex.MultiDex;

public class AppContext extends Application {

   ...

   @Override
   protected void attachBaseContext(Context base) {
     super.attachBaseContext(base);
     MultiDex.install(this);
   }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM