Original: 80050700
- The relationship between Androidstudio, Gradle and Buildtoolsversion
- Android Studio Gradle Plug-in version and Gradle version corresponding relationship
- Android Studio Upgrade to 3.1 problems encountered
- Problem one: The Configuration ' compile ' is obsolete and have been replaced with ' implementation ' and ' API '.
- The difference between API and implementation:
- Question two: The Sourceset ' instrumenttest ' isn't recognized by the Android Gradle Plugin. Perhaps you misspelled something?
- Issue three: Extractdebugannotations is incompatible with Java 8 sources and have been Disabled.extractreleaseannotations is Incompa Tible with Java 8 sources and have been disabled
- Issue four: Solve the problem of no such property:for_runtime for Class:org.gradle.api.attributes.Usage
The relationship between Androidstudio, Gradle and Buildtoolsversion
The Android Studio build system is based on Gradle, and the " Android plugin for Gradle adds several features" is specific to building Android apps.
Android Studio builds the system based on the Gradle, and in order to build Android apps, the Android Gradle plugin adds several features that are unique to building Android apps.
- Androidstudio: Google's official Android app development tool based on IntelliJ idea
- Gradle: is a tool and a programming framework. Use Gradle to complete the compilation and packaging of your app.
- Version of the Buildtoolsversion:android build tool, which contains the packaging tools AAPT, DX, and so on. Buildtoolsversion in the installation of the Android SDK path under the/build-tools/
Android Studio Gradle Plug-in version and Gradle version corresponding relationship
- Gradle plug-in version configuration: In a file corresponding to project
build.gradle
buildscript { repositories { /**Gradle 4.1 and higher include support for Google‘s Maven repo using the google() method. And you need to include this repo to download Android plugin 3.0.0 or higher.*/ jcenter() google() ... } dependencies { classpath ‘com.android.tools.build:gradle:3.1.1‘ }}allprojects { repositories { jcenter() google() }}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
buildscript定义了全局的相关属性
repositoriesDefine a warehouse: A warehouse represents the source of a dependent package, such as the Jcenter warehouse dependencies used to define the build process: The 仅仅需要定义默认的Android插件 plugin allows you to perform tasks related to Android, note that you should not define a dependency package for a submodule in the method body.
allprojectsUsed to define the default properties for each module: not just the default configuration, you can also create tasks in the Allprojects method body, which will be visible in all modules.
- Gradle version Configuration
In gradle/wrapper/gradle-wrapper.properties the file
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
- The Gradle plugin version and the Gradle version correspond to the following:
Website Link: https://developer.android.google.cn/studio/releases/gradle-plugin.html#updating-plugin
Android Studio Upgrade to 3.1 problems encountered
Android Studio升级为3.1,Gradle 4.4,buildToolsVersion 27.0.3所带来的问题
Problem one: The Configuration ' compile ' is obsolete and have been replaced with ' implementation ' and ' API '.
使用implementation或者api代替compile
dependencies { compile ‘com.google.dagger:dagger:2.11‘ compile ‘com.google.dagger:dagger-android:2.11‘ debugCompile ‘com.squareup.leakcanary:leakcanary-android:1.5.4‘ releaseCompile ‘com.squareup.leakcanary:leakcanary-android-no-op:1.5.4‘ }
dependencies { implementation ‘com.google.dagger:dagger:2.11‘ implementation ‘com.google.dagger:dagger-android:2.11‘ debugImplementation ‘com.squareup.leakcanary:leakcanary-android:1.5.4‘ debugImplementation ‘com.squareup.leakcanary:leakcanary-android-no-op:1.5.4‘ }
The difference between API and implementation:
API: module dependencies are exposed externally and can be referenced by dependent packages (exactly equivalent to compile directives)
Implementation: The 依赖只作用于当前的module dependency of the module is hidden inside, not externally exposed (dependencies using implementation directives are not passed)
There is a module_a dependent on glide (MODULE_A uses the implementation directive to rely on glide)
implementation ‘com.github.bumptech.glide:glide:3.7.0‘
Another module_b, dependent on module_a:
implementation project(‘:module_A‘)
At this time module_b inside cannot quote glide,module_B要想引用glide,就在module_A使用的是api来引用glide
‘com.github.bumptech.glide:glide:3.7.0‘
Compiled with implementation instructions, glide dependency on module is Module_b is not visible
Compile with API instructions, glide dependent on module is Module_b is visible
建议:在Google IO 中提到了一个建议,依赖首先应该设置为implementation的,如果没有错,那就用implementation,如果有错,那么使用api指令。`使用implementation会使编译速度有所增快。`
Question two: The Sourceset ' instrumenttest ' isn't recognized by the Android Gradle Plugin. Perhaps you misspelled something?
将instrumentTest改为 androidTest
A new version of Gradle renamed Instrumenttest
| older versions |
New version |
| Instrumenttestcompile |
Androidtestcompile |
| Instrumenttest |
Androidtest |
Issue three: Extractdebugannotations is incompatible with Java 8 sources and have been Disabled.extractreleaseannotations is Incompa Tible with Java 8 sources and have been disabled
Me.tatarka:gradle-retrolambda was used in the project,
{ classpath ‘me.tatarka:gradle-retrolambda:3.2.5‘}
The RETROLAMBDA has been upgraded to solve the problem
{ classpath ‘me.tatarka:gradle-retrolambda:3.7.0‘}
Issue four: Solve the problem of no such property:for_runtime for Class:org.gradle.api.attributes.Usage
dependencies { //classpath ‘com.novoda:bintray-release:0.5.0‘ classpath ‘com.novoda:bintray-release:0.8.0‘}
Upgrading the Com.novoda.bintray-release version
Android Studio upgrade to 3.1 step into the pit