【Android Studio】Android Studio Migrating Gradle Projects to version 1.0.0
2014-12-15 15:04
567 查看
http://tools.android.com/tech-docs/new-build-system
The Android Gradle plugin has been in rapid development, and as features evolved the APIs and the build file description language went through several incompatible changes. If you are trying to load a project that was built with an older version of the Gradle
plugin, it may not build correctly with 1.0.0.
This document describes the most common changes to help you migrate to 1.0.0. From version 1.0.0 and going forward, we will strive much harder to not make incompatible changes, and if we do, we plan to write IDE support to help migrate the projects automatically.
The build system knows which specific version of the Gradle plugin to use, and the version of Gradle to use, because they are listed explicitly in your project files. When you use Android Studio 1.0 and you open an older project, it will offer to automatically
find and update these version numbers. You can also make these edits manually.
The Android Gradle plugin version is typically listed in the top level
The version of Gradle to use for your project should also be updated to 2.2.1 or later. You can do that by editing the file
Again, Android Studio should offer to perform this edit automatically when you open up an older project:
The most common issue that affects users is the
Gradle DSL method not found: 'runProguard()'
then this is the cause of your build error.
This crops up a lot because that property was inserted into all projects created by Android Studio prior to version 0.14.0.
To update your project, edit your build.gradle file as follows:
There are some additional other properties that were renamed as well, in both build types and product flavors.
You cannot use applicationId to customize the package of a library project. The package name has to be fixed in library projects (and specified as packageName in the manifest). The Gradle plugin did not enforce this restriction earlier.
Version 0.9 of the Gradle plugin for Android made a few incompatible changes that require changes to your project. This page
documents how to update your project. Note that this is not a complete list of changes in the 0.9 version of the plugin; it simply covers the changes that require updates to your source files. For a full list of changes, see the user
guide.
Instrumentation Tests
If you have instrumentation tests (or other types of tests) in your project, note that we changed the name and folder from instrumentation tests to android tests to reflect the fact that this facility is not just for instrumentation tests but for plain JUnit
tests (running on a device) and eventually also UI automator tests.
To update your project
Rename your instrumentTest folders to androidTest, e.g. git
mv app/src/instrumentTest app/src/androidTest.
Alternatively you can tell gradle to keep using the old folder by relocating your sourcesets.
Update any 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 the library projects is now the same as for the application projects. This means you can create more build types, and create flavors.
You can create/configure more build types, in the buildTypes
{ ... } container.
You can create product flavors using the productFlavors
{ ... } container.
You can create signingConfigs using the signingConfigs
{ ... } container.
For example if you have in your library:
android {
debug {
}
release {
}
debugSigningConfig {
}
}
You would replace it with:
android {
buildTypes {
debug {
}
release {
}
}
signingConfigs {
debug {
}
}
}
http://tools.android.com/tech-docs/new-build-system
The Android Gradle plugin has been in rapid development, and as features evolved the APIs and the build file description language went through several incompatible changes. If you are trying to load a project that was built with an older version of the Gradle
plugin, it may not build correctly with 1.0.0.
This document describes the most common changes to help you migrate to 1.0.0. From version 1.0.0 and going forward, we will strive much harder to not make incompatible changes, and if we do, we plan to write IDE support to help migrate the projects automatically.
Update Plugin and Gradle Version Numbers
The build system knows which specific version of the Gradle plugin to use, and the version of Gradle to use, because they are listed explicitly in your project files. When you use Android Studio 1.0 and you open an older project, it will offer to automaticallyfind and update these version numbers. You can also make these edits manually.
The Android Gradle plugin version is typically listed in the top level
build.gradlefile in the project, and can be updated as follows:
dependencies {
- classpath 'com.android.tools.build:gradle:0.8.+'
+ classpath 'com.android.tools.build:gradle:1.0.0'
}
The version of Gradle to use for your project should also be updated to 2.2.1 or later. You can do that by editing the file
gradle/wrapper/gradle-wrapper.properties:
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
Again, Android Studio should offer to perform this edit automatically when you open up an older project:
Migrating from 0.9.x to 1.0.0
runProguard
The most common issue that affects users is the runProguardproperty changing names to
minifyEnabled. If you run into the build error
Gradle DSL method not found: 'runProguard()'
then this is the cause of your build error.
This crops up a lot because that property was inserted into all projects created by Android Studio prior to version 0.14.0.
To update your project, edit your build.gradle file as follows:
}
release {
- runProguard true
+ minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
There are some additional other properties that were renamed as well, in both build types and product flavors.
ApplicationId in Library Projects
You cannot use applicationId to customize the package of a library project. The package name has to be fixed in library projects (and specified as packageName in the manifest). The Gradle plugin did not enforce this restriction earlier.
Renamed Properties in BuildTypes
runProguard => minifyEnabled
zipAlign => zipAlignEnabled
jniDebugBuild => jniDebuggable
renderscriptDebug => renderscriptDebuggable
Renamed Properties in ProductFlavors
flavorGroups => flavorDimensions
packageName => applicationId
testPackageName => testApplicationId
renderscriptSupportMode => renderscriptSupportModeEnabled
ProductFlavor.renderscriptNdkMode => renderscriptNdkModeEnabled
Other Name changes
InstrumentTestwas renamed to
androidTest.
Migrating From 0.8.x to 0.9.x
Version 0.9 of the Gradle plugin for Android made a few incompatible changes that require changes to your project. This pagedocuments how to update your project. Note that this is not a complete list of changes in the 0.9 version of the plugin; it simply covers the changes that require updates to your source files. For a full list of changes, see the user
guide.
Instrumentation Tests
If you have instrumentation tests (or other types of tests) in your project, note that we changed the name and folder from instrumentation tests to android tests to reflect the fact that this facility is not just for instrumentation tests but for plain JUnit
tests (running on a device) and eventually also UI automator tests.
To update your project
Rename your instrumentTest folders to androidTest, e.g. git
mv app/src/instrumentTest app/src/androidTest.
Alternatively you can tell gradle to keep using the old folder by relocating your sourcesets.
Update any 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'
}
Libraries
The DSL for the library projects is now the same as for the application projects. This means you can create more build types, and create flavors.You can create/configure more build types, in the buildTypes
{ ... } container.
You can create product flavors using the productFlavors
{ ... } container.
You can create signingConfigs using the signingConfigs
{ ... } container.
For example if you have in your library:
android {
debug {
}
release {
}
debugSigningConfig {
}
}
You would replace it with:
android {
buildTypes {
debug {
}
release {
}
}
signingConfigs {
debug {
}
}
}
http://tools.android.com/tech-docs/new-build-system
相关文章推荐
- android studio gradle project sync failed,和android studio Error:Unable to start the daemon process问题
- Android Studio报错 :Failed to build project with Android studio
- 关于android studio出现Gradle sync failed: Plugin is too old, please update to a more recent version
- [Android Studio] Gradle fails to resolve dependencies in Android Studio
- Android Studio 更新报错:This version of Android studio is incompatible withe gradle plugin used.
- Android studio 运行出现Error running app: This version of Android Studio is incompatible with the Gradle
- Android studio提示Android studio 在gradle文件中引入support:appcompat-v7:22.2.0包的时候出现Failed to resolve的错误
- Android studio 运行出现Error running app: This version of Android Studio is incompatible with the Gradle
- Android studio 运行出现Error running app: This version of Android Studio is incompatible with the Gradle
- Cant migrate project to Gradle in Android Studio
- Android Studio 3.0 The android gradle plugin version 3.0.0-alpha1 is too old, update to the
- android studio build.gradle中 project.ANDROID_BUILD_SDK_VERSION
- Android Studio Gradle project sync failed,Gradle sync failed: Unable to start the daemon process.
- Android Studio(版本2.4)报错:the android gradle plugin version 2.4.0-alpha4 is too old, please update to
- 安装android studio 出现的路径问题 tools.jar' seems to be not in Android Studio classpath
- Android Studio Failed to complete Gradle execution
- Android studio 启动时出现Android studio was unable to create a local connection in order
- Android Studio新体验之android failed to complete gradle execution a fatal exception has occurred
- Say Hello To Android Studio【android studio 安装步骤概述】
- Android Studio从Eclipse工程导入时Failed to sync Gradle project