Android studio 1.0 RC更新

build.gradle改动:

1.buildTypes->release->runProguard()

这里是runProguard()方法被替换了,
把runProguard改为minifyEnabled即可。

2.productFlavors->google->packageName=’com.toprankapps.snapgrab’

这里是packageName=’com.alinaapps.privatealbum’已经被替换,
改成applicationId ‘com.alinaapps.privatealbum’。

3.buildTypes->applicationVariants.all

这里的applicationVariants.all方法中packageApplication这个属性被取消了。

原来:

applicationVariants.all { variant ->
apk = variant.packageApplication.outputFile;
newName = apk.name.replace(“.apk”, “-v” + defaultConfig.versionName + “.apk”);
newName = newName.replace(“app”, “PrivateAlbum”);
variant.packageApplication.outputFile = new File(apk.parentFile, newName);
if (variant.zipAlign) {
variant.zipAlign.outputFile = new File(apk.parentFile, newName.replace(“-unaligned”, “”));
}
}

现在:

applicationVariants.all{ variant ->
def apk = variant.outputs[0].outputFile;
def versionName = android.defaultConfig.versionName;
def newName = “”;
if (variant.buildType.name == “release”) {
newName = apk.name.replace(“.apk”, “_V” + versionName + “_release.apk”);
} else {
newName = apk.name.replace(“.apk”, “_V” + versionName + “_debug.apk”);
}
newName = newName.replace(“-“ + variant.buildType.name, “”);
variant.outputs[0].outputFile = new File(apk.parentFile, newName);
if (variant.outputs[0].zipAlign) {
variant.outputs[0].zipAlign.outputFile = new File(apk.parentFile, newName.replace(“-unaligned”, “”));
}
}

4.android studio中的plugin也发生了改变

这里是将”apply plugin: ‘android’,
改为”apply plugin: ‘com.android.application’

5. resConfigs,shrinkResources 去除无用资源

defaultConfig {

// …

resConfigs “en”, “de”, “fr”, “it”
resConfigs “nodpi”, “hdpi”, “xhdpi”, “xxhdpi”, “xxxhdpi”
}

保留指定资源目录,去除库项目可能存在的冗余资源

shrinkResources 使用注意项目是否存在反射获取资源

6. Java SDK 版本建议用 7 支持 Android API Level 8 及以上

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}

Added support for Java 7 language features like multi-catch, try-with-resources, and the diamond operator.

Try-with-resources requires minSdkVersion 19; the rest of the new language features require minSdkVersion 8 or higher.

项目规模较小可以考虑采用 JDK 8,lambda 有助于代码简洁,配合 Rxjava 是极好的

使用见 https://github.com/evant/gradle-retrolambda

Android Studio 对 lambda 的支持也是极好的