Gradle Android 工程開啟 multiDex

來源:互聯網
上載者:User

環境  Gradle 2.2 (如果版本不同.下面的指令碼是需要調整 com.android.tools.build:gradle 這個版本號碼的)


build.gradle  (注意標紅的地方)

buildscript {    repositories {        mavenCentral()    }    dependencies {        classpath 'com.android.tools.build:gradle:0.14.+'    }tasks.withType(JavaCompile) {options.encoding = "UTF-8"}}apply plugin: 'android'dependencies {    compile fileTree(dir: 'libs', include: '*.jar')}android {    compileSdkVersion 21    buildToolsVersion "21.1.1"lintOptions {abortOnError false}compileOptions {sourceCompatibility JavaVersion.VERSION_1_6targetCompatibility JavaVersion.VERSION_1_6}defaultConfig {minSdkVersion 14targetSdkVersion 21multiDexEnabled = true}    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')    }signingConfigs {release {storeFile file("TalkwebMBI.keystore")storePassword "***"keyAlias "***"keyPassword "***"}}dexOptions {preDexLibraries = false }afterEvaluate {tasks.matching {   it.name.startsWith('dex')}.each { dx ->   if (dx.additionalParameters == null) {  dx.additionalParameters = ['--multi-dex']   } else {  dx.additionalParameters += '--multi-dex'   }} }//聲明此發布構建在簽名之前需要運行proguardbuildTypes {release {minifyEnabled trueproguardFile getDefaultProguardFile('proguard-android.txt')proguardFile 'proguard.cfg'signingConfig signingConfigs.release}}}

proguard.cfg

# This is a configuration file for ProGuard.# http://proguard.sourceforge.net/index.html#manual/usage.html-dontusemixedcaseclassnames-dontskipnonpubliclibraryclasses-verbose# Optimization is turned off by default. Dex does not like code run# through the ProGuard optimize and preverify steps (and performs some# of these optimizations on its own).#-dontoptimize-dontpreverify#-dontshrink# If you want to enable optimization, you should include the# following:#-optimizations !code/simplification/arithmetic,!code/simplification/cast,!field/*,!class/merging/*#-optimizationpasses 5#-allowaccessmodification#-dontpreverify## Note that you cannot just include these flags in your own# configuration file; if you are including this file, optimization# will be turned off. You'll need to either edit this file, or# duplicate the contents of this file and remove the include of this# file from your project's proguard.config path property.-keepattributes InnerClasses-keepattributes Signature-keepattributes *Annotation*-keep @interface *-keep enum * { *; }# Android:-keep public class * extends android.app.Activity-keep public class * extends android.app.Application-keep public class * extends android.app.Service-keep public class * extends android.content.BroadcastReceiver-keep public class * extends android.content.ContentProvider-keep public class * extends android.app.backup.BackupAgent-keep public class * extends android.preference.Preference#-keep public class * extends android.support.v4.app.Fragment#-keep public class * extends android.app.Fragment-keep public class com.android.vending.licensing.ILicensingService# For native methods, see http://proguard.sourceforge.net/manual/examples.html#native-keepclasseswithmembernames class * {    native <methods>;}-keep public class * extends android.view.View {    public <init>(android.content.Context);    public <init>(android.content.Context, android.util.AttributeSet);    public <init>(android.content.Context, android.util.AttributeSet, int);    public void set*(...);}-keepclasseswithmembers class * {    public <init>(android.content.Context, android.util.AttributeSet);}-keepclasseswithmembers class * {    public <init>(android.content.Context, android.util.AttributeSet, int);}-keepclassmembers class * extends android.app.Activity {   public void *(android.view.View);}# For enumeration classes, see http://proguard.sourceforge.net/manual/examples.html#enumerations-keepclassmembers enum * {    public static **[] values();    public static ** valueOf(java.lang.String);}-keep class * implements android.os.Parcelable {  public static final android.os.Parcelable$Creator *;  <init>(android.os.Parcel);}-keepclassmembers class **.R$* {    public static <fields>;}# The support library contains references to newer platform versions.# Don't warn about those in case this app is linking against an older# platform version.  We know about them, and they are safe.-dontwarn android.support.**-dontwarn javax.xml.**-keep class * extends java.util.ListResourceBundle { protected Object[][] getContents(); }#------------LIBS---------------------keep class android.support.** { public *; }


相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.