Android Official Technical document translator--Migrate Gradle project to 1.0.0 version

Source: Internet
Author: User

This article is translated from the official Android technical document "migrating Gradle Projects to version 1.0.0", original address: http://tools.android.com/tech-docs/ new-build-system/migrating-to-1-0-0.

This document describes how the lower version of the Gradle project was upgraded to version 1.0.0.

Translation is not easy, reprint please indicate the source of CSDN blog:

http://blog.csdn.net/maosidiaoxian/article/details/42772727

If you think the translation is OK, please click on the "Top" at the end of the article, if you have inappropriateness, please correct me. Thank you.


migrating Gradle projects to version 1.0.0Android's Gradle plugin has developed rapidly, and as an evolutionary feature, the API and the description language of the build file have undergone some incompatible changes. If you are trying to load a project built with an older version of the Gradle plug-in, it may not build correctly with the 1.0.0 version.
This document describes most of the common changes to help you migrate to 1.0.0. We will endeavour not to make incompatible changes from 1.0.0 and later versions. If we do, we're going to write IDE support to help automate the migration of projects. Update plugin and Gradle version number build system know which version of the Gradle plugin to use, and which version of Gradle. Because they are all explicitly listed in your project file. When you use Android Studio 1.0 and open an old project, it proactively proposes to automatically find and update these version numbers. You can also edit these version numbers manually.
Android Gradle plugin version is usually the top of the list in the project build.gradleFile, and can be updated to the following:
     dependencies { -        classpath ‘com.android.tools.build:gradle:0.8.+‘ +        classpath ‘com.android.tools.build:gradle:1.0.0      }
The version of Gradle that you use for your project should also be updated to 2.2.1 or later. You can edit it by gradle/wrapper/gradle-wrapper.propertiesFile to complete:  zipStorePath=wrapper/dists -distributionUrl=http\://services.gradle.org/distributions/gradle-1.11-all.zip +distributionUrl=http\://services.gradle.org/distributions/gradle-2.2.1-all.zip
Besides, when you open an old project, Android Studio should have the offer to perform this edit automatically:Since 0.9. xThe most common problem with migrating to 1.0.0runProguard is the impact on users runProguardProperty name changed to minifyEnabled。 If you experience the following build errorsGradle DSL Method not found: ' Runproguard () 'so that's why you build the error.
A lot of these problems occur because that attribute is inserted into all projects created by Android Studio before the 0.14.0 version.
If you want to upgrade your project, edit your Build.gradle file as follows:          }          release { -            runProguard true +            minifyEnabled true              proguardFiles getDefaultProguardFile(‘proguard-android.txt‘), ‘proguard-rules.txt‘

In the build type (build types) and product flavors, there are some other properties that have also been renamed.

ApplicationID in a class library project

You cannot use ApplicationID to customize the package name of a library project. The package name must be fixed in the library project (and specified in PackageName in the list). Earlier, the Gradle plugin did not enforce this constraint.

Properties renamed in Buildtypes runProguard => minifyEnabled zipAlign => zipAlignEnabled jniDebugBuild => jniDebuggable renderscriptDebug => renderscriptDebuggableProperties renamed in Productflavors flavorGroups => flavorDimensions packageName => applicationId testPackageName => testApplicationId renderscriptSupportMode => renderscriptSupportModeEnabled ProductFlavor.renderscriptNdkMode => renderscriptNdkModeEnabledOther Name changes InstrumentTestwas renamed to androidTest. Migrating from 0.8.x to 0.9.x
Gradle's Android plugin (Gradle plugin for Android) has made some incompatible changes to the 0.9 version, and these modifications require your project to be updated as well. This page of documentation describes how to update your project. Note that this is not a complete list of changes made in the 0.9 version of this plugin; it only covers those changes that require your source files to be updated. For a complete list of these modifications, see.User Guide
Instrumentation TestsIf you already have a instrumentation test (or other type of test) in your project, be aware that we have changed the name and folder from the instrumentation test to the Android test to reflect the fact. The fact is that this feature is not just a instrumentation test, it also contains a common JUnit test (running on one device) and the final UI Automator test.
If you want to update your project
  • Rename your instrumenttest folder to Androidtest, such as git mv app/src/instrumenttest app/src/androidtest .
    Alternatively, you can also tell Gradle to continue using the old folder by re-setting your sourcesets.
  • Update all the test dependencies from Instrumenttestcompile to Androidtestcompile:
    dependencies {
    -Instrumenttestcompile ' com.jayway.android.robotium:robotium-solo:4.3.1 '
    + androidtestcompile ' com.jayway.android.robotium:robotium-solo:4.3.1 '
    }
The DSL for library projects is now the same for the application project. This means that you can create more build types, and create flavors.
  • you can be in buildtypes {...} Create or configure more build types in the container.
  • You can use productflavors {...} The container creates the product flavors.
  • You can pass signingconfigs {...} container to create Signingconfigs.
For example, if you have the following configuration in your library project:
android {     Debug {         Release {    
debugsigningconfig { }
}

you are going to replace it with:
Android { Buildtypes { Debug {         } Release {         }     }
Signingconfigs {
Debug { }
    }
}

Android Official Technical document translator--Migrate Gradle project to 1.0.0 version

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.