在发布我的android应用程序到生产之前,我应该在我的build.gradle中做什么更改

问题描述:

这是更多的建议对我的build.gradle所做的更改,因为我即将发布我的第一个android应用程序。但没有令人满意的solution.Here是我gradle这个文件在发布我的android应用程序到生产之前,我应该在我的build.gradle中做什么更改

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

dependencies { 
    classpath 'io.fabric.tools:gradle:1.+' 
} 
} 
apply plugin: 'com.android.application' 
apply plugin: 'io.fabric' 

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


android { 
compileSdkVersion 25 
buildToolsVersion "25.0.2" 
defaultConfig { 
    applicationId "com.example.app" 
    minSdkVersion 19 
    targetSdkVersion 25 
    multiDexEnabled true 
    versionCode 1 
    versionName "1.0" 
    resConfigs "en_US", "hi_IN" 
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 
} 
buildTypes { 
    release { 
     minifyEnabled true 
     proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
    } 
} 
packagingOptions { 
    exclude 'META-INF/LICENSE' 
    exclude 'META-INF/DEPENDENCIES' 
    exclude 'META-INF/LICENSE-FIREBASE.txt' 
    exclude 'META-INF/NOTICE' 
} 

} 

dependencies { 
compile fileTree(dir: 'libs', include: ['*.jar']) 
compile('com.digits.sdk.android:digits:[email protected]') { 
    transitive = true; 

} 
compile('com.crashlytics.sdk.android:crashlytics:[email protected]') { 
    transitive = true; 
} 
compile('io.fabric.sdk.android:fabric:[email protected]') { 
    transitive = true; 
} 
compile 'com.android.support:multidex:1.0.1' 
compile 'com.android.support:appcompat-v7:25.3.1' 
compile 'com.android.support:customtabs:25.3.1' 
compile 'com.android.support:support-v13:25.3.1' 
compile 'com.android.support:design:25.3.1' 
compile 'com.android.support:gridlayout-v7:25.3.1' 
compile 'com.android.support:cardview-v7:25.3.1' 
compile 'com.android.support:recyclerview-v7:25.3.1' 
compile 'com.android.support:support-annotations:25.3.1' 
compile 'de.hdodenhof:circleimageview:1.3.0' 
compile 'com.github.bumptech.glide:glide:3.7.0' 
compile 'com.google.code.gson:gson:2.7' 
compile 'com.google.android.gms:play-services-location:10.2.1' 
compile 'com.google.android.gms:play-services-places:10.2.1' 
compile 'com.google.firebase:firebase-database:10.2.1' 
compile 'com.google.firebase:firebase-core:10.2.1' 
compile 'com.google.firebase:firebase-auth:10.2.1' 
compile 'com.google.firebase:firebase-messaging:10.2.1' 
compile 'com.google.firebase:firebase-crash:10.2.1' 
compile 'com.firebaseui:firebase-ui-database:1.2.0' 
compile 'com.google.firebase:firebase-storage:10.2.1' 
compile 'com.google.firebase:firebase-appindexing:10.2.1' 
compile ('io.branch.sdk.android:library:2.5.9') { 
    transitive = true; 
    exclude module: 'answers-shim'; 
} 

} 
apply plugin: 'com.google.gms.google-services' 

的每一个建议事项,也可能是其他的初学者和我一样谁正计划推出他们的第一个构建在Play商店的帮助。

我可以看到你已经在你的发布模式中启用了职业警卫。我建议你考虑从android doc下面的语句

对于更多的代码缩小,请尝试位于相同位置的proguard-android-optimize.txt文件。它包含相同的ProGuard规则,但其他优化可在字节码级别(内部和各种方法)执行分析,从而进一步缩小APK大小并帮助其更快运行。

改变这种

proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'

这个

proguardFiles getDefaultProguardFile('**proguard-android-optimize.txt**'), 'proguard-rules.pro' 

同时添加这为发布模式

shrinkResources true 

而且不要忘了加亲卫队的规则,如果你还没有。

做以上两件事情会让你的应用程序体积变小并且更加优化。

+0

亲职守规则?如何在我的文件中定义它们。 – Shubhendra

+0

@Shubhendra你需要在你的程序的proguard-rules.pro文件中定义它们。如果你不知道它们,你需要阅读它们。这里是链接到proguard官方手册。 https://www.guardsquare.com/en/proguard/manual/usage。如果有帮助,请将我的答案标记为已接受。 –

+0

明白了@ v4_adi,并且我也检查了有关职业守则规则的firebase文档。干杯:-) – Shubhendra