我的应用程序超过 64k 个方法,所以我应该实现 Multidex , 最初我有问题,因为“本地路径不存在”我解决了这个问题,现在 gradle 生成了 classes1.dex 和 classes2.dex, 但不能在低于 Lollipop 的情况下工作。它在 Lollipop 中工作正常,因为它具有 native 支持。错误说“<1st activity> is not present in dex path”
在看了一些教程后,他们说必须对 1.gradle 2.application class 3.manifest 进行更改
我对应用程序类了解不多..请指导我谢谢
注意:这是从eclipse导入的项目。
请检查build.gradle文件
apply plugin: 'com.android.application'
android {
defaultConfig {
compileSdkVersion 23
buildToolsVersion '23.0.1'
minSdkVersion 15 //lower than 14 doesn't support multidex
targetSdkVersion 23
}
dexOptions {
jumboMode = true
preDexLibraries = false
javaMaxHeapSize "2048M"
}
afterEvaluate {
tasks.matching {
it.name.startsWith('dex')
}.each { dx ->
if (dx.additionalParameters == null) {
dx.additionalParameters = ['--multi-dex']
} else {
dx.additionalParameters += '--multi-dex'
}
}
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
// Move the tests to tests/java, tests/res, etc...
instrumentTest.setRoot('tests')
// Move the build types to build-types/<type>
// For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
// This moves them out of them default location under src/<type>/... which would
// conflict with src/ being used by the main source set.
// Adding new build types or product flavors should be accompanied
// by a similar customization.
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
productFlavors {
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.android.support:multidex:1.0.1'
}
最佳答案
您遵循了一个教程,该教程展示了如何在Android gradle 插件支持多 dex 之前手动添加它。从 v0.14.0 开始,您需要做的就是添加:
android {
defaultConfig {
...
multiDexEnabled true
}
并且您可以选择三个选项之一来调用 MultiDex 代码。来自 MultiDexApplication documentation :
Minimal MultiDex capable application. To use the legacy multidex library there is 3 possibilities:
- Declare this class as the application in your AndroidManifest.xml.
- Have your Application extends this class.
- Have your Application override attachBaseContext starting withprotected void attachBaseContext(Context base) { super.attachBaseContext(base); MultiDex.install(this); }
不要忘记从构建脚本中删除 afterEvaluate
block 。
确保您已阅读 official documentation .
关于android - 多索引 :no class found exception,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32789002/