Official Android Technical Documentation translation-migrate the Gradle project to version 1.0.0 and androidgradle

Source: Internet
Author: User

Official Android Technical Documentation translation-migrate the Gradle project to version 1.0.0 and androidgradle

This article is translated from the official Android Technical Documentation Migrating Gradle Projects to version 1.0.0. Original address: http://tools.android.com/tech-docs/new-build-system/migrating-to-1-0-0-0.

This document describes how to upgrade the Gradle project of a lower version to version 1.0.0.

It is not easy to translate. For more information, see the source on the CSDN blog:

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

Translation is time-consuming. If you think the translation is still OK, click "TOP" at the end of the article. If any error occurs, please correct me. Thank you.


The Gradle plug-in for migrating the Gradle project to Android 1.0.0 has developed rapidly. As an evolutionary feature, the description language of the API and build file has also undergone some incompatible changes. If you are trying to load a project built with the old version of Gradle plug-in, it may not be built correctly through version 1.0.0.
This document describes most common changes to help you migrate to 1.0.0. From version 1.0.0 and later, we will try our best not to make incompatible changes. If we do, we plan to write IDE support to help automate migration of projects. Update the plug-in and Gradle version number. The build system knows which version of Gradle plug-in to be used and which version of Gradle is used. Because they are all explicitly listed in your project files. When you use Android Studio 1.0 and open an old project, it automatically finds and updates these versions. You can also manually edit these versions.
The Android Gradle plug-in version is usually top-level 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 Gradle version used by your project should also be updated to 2.2.1 or later. You can edit 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
In addition, when you open an old project, Android Studio should provide automatic execution of this EDIT: from 0.9. XThe most common problems that affect users when migrating to 1.0.0runProguard are: runProguardAttribute name changed minifyEnabled. If you encounter the following build error Gradle DSL method not found: 'runproguard () ', this is why your build error occurs.
This problem occurs suddenly because the attribute is inserted to all projects created by Android Studio before version 0.14.0.
To upgrade your project, edit your build. gradle file as follows:          }          release { -            runProguard true +            minifyEnabled true              proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'

Some other attributes are also renamed in build types and product flavors.

ApplicationId in the class library project

You cannot use applicationId to customizeLibraryThe package name of the project. The package name must be fixed in the library project (and specified in packageName ). Earlier, the Gradle plug-in did not force this constraint.

Attributes renamed in BuildTypes runProguard => minifyEnabled zipAlign => zipAlignEnabled jniDebugBuild => jniDebuggable renderscriptDebug => renderscriptDebuggableAttributes renamed in ProductFlavors flavorGroups => flavorDimensions packageName => applicationId testPackageName => testApplicationId renderscriptSupportMode => renderscriptSupportModeEnabled ProductFlavor.renderscriptNdkMode => renderscriptNdkModeEnabledOther Name Changes InstrumentTestWas renamed androidTest. Migrate from 0.8.x to 0.9.x
Version 0.9 of Gradle's Android plug-in (Gradle plugin for Android) has made some incompatible changes. These changes need to be updated for your project. This page describes how to update your project. Note that this is not a complete list of changes made in this plug-in version 0.9; it only covers the changes that need to be updated for your source files. For a complete list of these changes, see. User Guide.
Instrumentation Tests if you have an instrumentation Test (or another type of test) in your project, note that we change the name and folder from the instrumentation test to the android test, to reflect a fact. The fact is that this function is not only an instrumentation test, but also contains a general JUnit test (running on a device) and a final UI automation test.
If you want to update your project
  • Rename your instrumentTest folder to androidTest, for example, git mv app/src/instrumentTest app/src/androidTest.
    Alternatively, you can reset your sourcesets to tell gradle to continue using the old folder.
  • Update all test Dependencies from instrumentTestCompile to androidTestCompile:
    Dependencies {
    -InstrumentTestCompile 'com. jayway. android. robobench: robobench-solo: 4.3.1'
    + AndroidTestCompile 'com. jayway. android. robobench: robobench-solo: 4.3.1'
    }
The DSL used by the Library Project is now the same as the application project. This means that you can create more build types and create flavors.
  • You can create or configure more build types in the buildTypes {...} container.
  • You can use the productFlavors {...} container to create product flavors.
  • You can use the signingConfigs {...} container to create signingConfigs.
For example, if you have the following configurations in your library project:
Android {debug {} release {}
DebugSigningConfig {}
}

You will replace it:
Android {buildTypes {debug {} release {}}
SigningConfigs {
Debug {}
}
}

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.