Sid*_*t N 11 android android-multidex
我有一个项目,我已经启用multidex了避免65k limit,并且productFlavors(开发API 21和prod API 19)进行自定义.建立我的项目API 21即开发风味是成功的,但在API 19prod风味,它不断给我在应用程序任务中的例外shrink{component}MultiDexComponents
完整错误日志:
:app:shrinkProdDebugMultiDexComponents FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:shrinkProdDebugMultiDexComponents'.
> java.io.IOException: Can't read [{Project Path}/app/build/intermediates/multi-dex/prod/debug/allclasses.jar] (Can't process class [com/olivephone/office/a/b/e/p.class] (Unknown verification type [17] in stack map frame))
Run Code Online (Sandbox Code Playgroud)
的build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion '23.0.0'
defaultConfig {
applicationId '{Project Name}'
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
multiDexEnabled true
}
productFlavors {
dev {
// dev utilizes minSDKVersion = 21 to allow the Android gradle plugin
// to pre-dex each module and produce an APK that can be tested on
// Android Lollipop without time consuming dex merging processes.
minSdkVersion 21
}
prod {
// The actual minSdkVersion for the application.
minSdkVersion 19
}
}
buildTypes {
release {
minifyEnabled false
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:recyclerview-v7:23.0.1'
compile 'com.android.support:cardview-v7:23.0.1'
compile 'com.oguzdev:CircularFloatingActionMenu:1.0.2'
compile 'com.google.code.gson:gson:2.3.1'
compile 'com.google.android.gms:play-services:8.1.0'
compile 'com.android.support:multidex:1.0.1'
compile files('libs/linkedin-j-android.jar')
compile files('libs/itsrts-pptviewer.jar')
compile files('libs/signpost-core-1.2.1.1.jar')
compile 'org.twitter4j:twitter4j-core:4.0.2'
compile files('libs/universal-image-loader-1.9.2-SNAPSHOT-with-sources.jar')
compile files('libs/dropbox-android-sdk-1.6.3.jar')
compile files('libs/json_simple-1.1.jar')
compile 'com.joanzapata.pdfview:android-pdfview:1.0.1@jar'
compile 'com.facebook.android:facebook-android-sdk:4.1.0'
}
Run Code Online (Sandbox Code Playgroud)
有人请帮忙吗?
Bha*_*iya 10
适用于Android 5.0及更高版本的Multidex支持
Android 5.0及更高版本使用名为ART的运行时,它本身支持从应用程序APK文件加载多个dex文件.ART在应用程序安装时执行预编译,扫描类(.. N).dex文件并将它们编译成单个.oat文件以供Android设备执行.有关Android 5.0运行时的更多信息,请参阅ART简介.
这就是为什么您的应用在API级别21上正常运行的原因.
Android 5.0之前的Multidex支持
Android 5.0之前的平台版本使用Dalvik运行时来执行应用程序代码.默认情况下,Dalvik将应用程序限制为每个APK的单个classes.dex字节码文件.为了解决这个限制,您可以使用multidex支持库,它将成为应用程序主要DEX文件的一部分,然后管理对其他DEX文件及其包含的代码的访问.
所以,首先要确保你已经导入了正确的依赖,这似乎你做到了.
dependencies {
compile 'com.android.support:multidex:1.0.0'
}
Run Code Online (Sandbox Code Playgroud)
在清单中MultiDexApplication,将multidex支持库中的类添加到application元素中.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android.multidex.myapplication">
<application
...
android:name="android.support.multidex.MultiDexApplication">
...
</application>
</manifest>
Run Code Online (Sandbox Code Playgroud)
替代方案,如果您的应用程序扩展了Application类,您可以覆盖该attachBaseContext()方法并调用MultiDex.install(this)enable multidex.
public void onCreate(Bundle arguments) {
MultiDex.install(getTargetContext());
super.onCreate(arguments);
...
}
Run Code Online (Sandbox Code Playgroud)
我希望它会帮助你.
请更改您的依赖项,如下所示:
编辑后的依赖项:
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.android.support:recyclerview-v7:23.0.1'
compile 'com.android.support:cardview-v7:23.0.1'
compile 'com.oguzdev:CircularFloatingActionMenu:1.0.2'
compile 'com.google.code.gson:gson:2.3.1'
compile 'com.google.android.gms:play-services:8.1.0'
compile 'com.android.support:multidex:1.0.1'
compile 'com.googlecode.linkedin-j:linkedin-j-core:1.0.416'
compile 'oauth.signpost:signpost-core:1.2.1.2'
compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.4'
compile 'com.googlecode.json-simple:json-simple:1.1'
compile 'org.twitter4j:twitter4j-core:4.0.2'
compile files('libs/itsrts-pptviewer.jar')
compile files('libs/dropbox-android-sdk-1.6.3.jar')
compile 'com.joanzapata.pdfview:android-pdfview:1.0.1@jar'
compile 'com.facebook.android:facebook-android-sdk:4.1.0'
Run Code Online (Sandbox Code Playgroud)
原因是 'compile fileTree(dir: 'libs', include: ['*.jar'])' 包含 libs 文件夹中要 gradle 的所有 jar 文件。
谢谢。!!
| 归档时间: |
|
| 查看次数: |
13021 次 |
| 最近记录: |