gpt4 book ai didi

android - Dagger 2 和 Multidex 应用程序

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:10:14 25 4
gpt4 key购买 nike

我正在使用支持 Android 注入(inject)的 Dagger 2.11。添加大量依赖项后,我被迫启用 MultiDex。

添加了对 Multidex 的支持,在 Android 4.4 上运行正常,在 Android >=6 上运行良好。

该问题仅出现在 Android 5 和 5.1 上,我收到以下错误:

Caused by: java.lang.ClassNotFoundException: Didn't find class "dagger.internal.Preconditions" on path: DexPathList[[zip file...

我尝试将 "dagger.internal.Preconditions" 添加到我在 multiDexKeepProguard 中使用的文件中,但没有成功。

build.gradle 文件

buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
}

dependencies {
classpath 'io.fabric.tools:gradle:1.+'
}
}

repositories {
maven { url 'https://maven.fabric.io/public' }
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
apply plugin: 'com.tmiyamon.config'

apply plugin: 'me.tatarka.retrolambda'
apply plugin: 'com.tmiyamon.config'
apply plugin: 'realm-android'

android {
compileSdkVersion 25
buildToolsVersion "25.0.3"
defaultConfig {
applicationId "appId"
minSdkVersion 19
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
multiDexEnabled true

}
dexOptions {
preDexLibraries false
javaMaxHeapSize "4g"
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

signingConfigs {
debug {
storeFile file("path")
keyAlias "alias"
storePassword "password"
keyPassword "password"
}

release {
storeFile file("path")
keyAlias "alias"
storePassword "password"
keyPassword "password"
}
}

buildTypes {
debug {
signingConfig signingConfigs.debug
minifyEnabled false
zipAlignEnabled false
testCoverageEnabled false
multiDexKeepProguard file('multidex-config.pro')
proguardFiles fileTree(dir: 'proguard').asList().toArray()
}
release {
minifyEnabled true
multiDexKeepProguard file('multidex-config.pro')
proguardFiles fileTree(dir: 'proguard').asList().toArray()
signingConfig signingConfigs.release
}
}

productFlavors {
local {
applicationIdSuffix ".local"
versionNameSuffix " Local " + calculateVersionNameSuffix()
}

staging {
applicationIdSuffix ".staging"
versionNameSuffix " Staging " + calculateVersionNameSuffix()
}

production {

}
}
}
dependencies {
long list of dependencies
}

和 list 文件:

<manifest package="package"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<< permissions >>
<!--${applicationId}-->
<application
android:name=".application.MyApplication"
android:allowBackup="false"
android:icon="@mipmap/ic_launcher"
android:label="${launcherAppName}"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme"
tools:replace="android:label">
<activity
android:name=".ui.startup.StartupActivity"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>

rest of the Manifest....

最佳答案

好吧,最后我找到了解决办法。

我还添加了

multiDexKeepFile file('multidex-config.txt')

进入 buiild.gradle 文件的 buildTypes 部分。

现在看起来像下面这样:

 release {
minifyEnabled true
zipAlignEnabled true
multiDexKeepFile file('multidex-config.txt')
multiDexKeepProguard file('multidex-config.pro')
proguardFiles fileTree(dir: 'proguard').asList().toArray()
signingConfig signingConfigs.release
debuggable false
}

multidex-config.txt 具有以下内容:

dagger/internal/Preconditions.class

关于android - Dagger 2 和 Multidex 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45820264/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com