Android MultiDexApplication not recognized
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26557737/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
MultiDexApplication not recognized
提问by JMRboosties
Trying to use MultiDexApplication in my app, but the class is not recognized when I try to extend my application activity with it.
Trying to use MultiDexApplication in my app, but the class is not recognized when I try to extend my application activity with it.
Here is my build.gradle file:
Here is my build.gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion '21.0.1'
defaultConfig {
applicationId 'com.myapp'
minSdkVersion 10
targetSdkVersion 21
versionCode 115
versionName '4.8'
}
buildTypes {
debug {
debuggable true
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
release {
debuggable false
runProguard true
zipAlign true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
packagingOptions {
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
}
lintOptions {
checkReleaseBuilds false
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.google.android.gms:play-services:6.1.11'
compile 'com.android.support:appcompat-v7:21.0.0'
compile 'com.nineoldandroids:library:2.4.0'
compile 'com.viewpagerindicator:library:2.4.1@aar'
compile project(':facebook')
}
You can see that I'm compiling on 21, using the latest build tools, and the latest google play services and support library.
You can see that I'm compiling on 21, using the latest build tools, and the latest google play services and support library.
Has anyone gotten this to work?
Has anyone gotten this to work?
回答by Alex Lipov
MultiDexApplication class is not part of appcompat-v7 library. It is being shipped in a separate jar (called android-support-multidex).
MultiDexApplication class is not part of appcompat-v7 library. It is being shipped in a separate jar (called android-support-multidex).
Find the android-support-multidex.jarunder /sdk/extras/android/support/multidex/library/libs(available from revision 21 of support library) and copy it to your project's libsfolder.
Find the android-support-multidex.jarunder /sdk/extras/android/support/multidex/library/libs(available from revision 21 of support library) and copy it to your project's libsfolder.
Update (11/5/2014):
The jar is now available in central repository:
Update (11/5/2014):
The jar is now available in central repository:
dependencies {
...
compile 'com.android.support:multidex:1.0.0'
}
For more info, see here.
For more info, see here.
回答by jossiwolf
Although this question is quite old, I got this error in a multi-module setup when trying to build the different modules together as one APK for API < 21. I already refactored to AndroidX, but the multidex docs don't mention AndroidX yet.
Although this question is quite old, I got this error in a multi-module setup when trying to build the different modules together as one APK for API < 21. I already refactored to AndroidX, but the multidex docs don't mention AndroidX yet.
If you are using AndroidX, make sure to replace the old multidex dependency
If you are using AndroidX, make sure to replace the old multidex dependency
compile 'com.android.support:multidex:1.0.3'
with the new one
with the new one
implementation 'androidx.multidex:multidex:2.0.0'
回答by gswierczynski
I have followed THISblog post according to which MultiDexApplication should be included in r21 of support library.
I have followed THISblog post according to which MultiDexApplication should be included in r21 of support library.
My IDE had trouble resolving it also.
My IDE had trouble resolving it also.
I made it work for now with the help of MULTIDEXgithub project by adding (you can see more details on the project's page):
I made it work for now with the help of MULTIDEXgithub project by adding (you can see more details on the project's page):
android {
dexOptions {
preDexLibraries = false
}
}
repositories {
jcenter()
}
dependencies {
compile 'com.google.android:multidex:0.1'
}
afterEvaluate {
tasks.matching {
it.name.startsWith('dex')
}.each { dx ->
if (dx.additionalParameters == null) {
dx.additionalParameters = []
}
dx.additionalParameters += '--multi-dex' // enable multidex
dx.additionalParameters += "--main-dex-list=$projectDir/multidex.keep".toString()
}
}
and adding $project_dir/multidex.keep file with following contents:
and adding $project_dir/multidex.keep file with following contents:
android/support/multidex/BuildConfig.class
android/support/multidex/MultiDex$V14.class
android/support/multidex/MultiDex$V19.class
android/support/multidex/MultiDex$V4.class
android/support/multidex/MultiDex.class
android/support/multidex/MultiDexApplication.class
android/support/multidex/MultiDexExtractor.class
android/support/multidex/MultiDexExtractor.class
android/support/multidex/ZipUtil$CentralDirectory.class
android/support/multidex/ZipUtil.class
The github project page mentions also some consideration for the contents of your implementation of MultiDexApplication class:
The github project page mentions also some consideration for the contents of your implementation of MultiDexApplication class:
- The static fields in your application class will be loaded before the MultiDex#installbe called! So the suggestion is to avoid static fields with types that can be placed out of main classes.dex file.
- The methods of your application class may not have access to other classes that are loaded after your application class. As workarround for this, you can create another class (any class, in the example above, I use Runnable) and execute the method content inside it.
- The static fields in your application class will be loaded before the MultiDex#installbe called! So the suggestion is to avoid static fields with types that can be placed out of main classes.dex file.
- The methods of your application class may not have access to other classes that are loaded after your application class. As workarround for this, you can create another class (any class, in the example above, I use Runnable) and execute the method content inside it.
回答by Luis Alberto Saucedo Quiroga
I got the solution :)
I got the solution :)
Upgrade to jdk 8 and change JDK location in Android Studio in
Upgrade to jdk 8 and change JDK location in Android Studio in
File > Project Structure > SDK Location
File > Project Structure > SDK Location
Find and change JDK location and click OK
Find and change JDK location and click OK