1、添加Gradle环境变量
bash gradle command not found
需要的命令行
open .bash_profile
添加
export GRADLE_HOME=/Applications/Android\ Studio.app/Contents/gradle/gradle-4.4
export PATH=${PATH}:${GRADLE_HOME}/bin
刷新一下,配置的环境变量才会生效
source .bash_profile
当我们再次运行提示没有权限
gradle: Permission denied
需要执行chmod
chmod +x /Applications/Android\ Studio.app/Contents/gradle/gradle-4.4/bin/gradle
别忘了刷新 source .bash_profile
2、查看冲突
进入今天的重点命令行,曾几何时刚接触grdale因为环信的一次冲突差点通宵,看来自己不带脑子写代码已经好久了。。。。
gradle -q :app:dependencies
gradle -q :app:dependencies
compile - Classpath for compiling the main sources.
+--- project :stickyDecoration
| \--- com.android.support:recyclerview-v7:25.1.0
| +--- com.android.support:support-annotations:25.1.0
| +--- com.android.support:support-compat:25.1.0
| | \--- com.android.support:support-annotations:25.1.0
| \--- com.android.support:support-core-ui:25.1.0
| +--- com.android.support:support-annotations:25.1.0
| \--- com.android.support:support-compat:25.1.0 (*)
+--- project :apmTools
+--- com.android.support:appcompat-v7:22.1.0
| +--- com.android.support:support-annotations:22.1.0
| +--- com.android.support:support-v4:22.1.0
| | +--- com.android.support:support-compat:22.1.0 (*)
| | +--- com.android.support:support-media-compat:22.1.0
| | | +---
+--- com.jakewharton:butterknife:8.6.0
| +--- com.jakewharton:butterknife-annotations:8.6.0
| | \--- com.android.support:support-annotations:25.1.0
| +--- com.android.support:support-annotations:25.1.0
| \--- com.android.support:support-compat:25.1.0 (*)
\--- com.scwang.smartrefresh:SmartRefreshLayout:1.0.5.1
发现support-annotations不一致
有两种解决方式
- force
- exclude
configurations.all {
resolutionStrategy {
force 'org.hamcrest:hamcrest-core:1.3'
}
}
dependencies {
androidTestCompile('com.android.support.test:runner:0.2')
androidTestCompile('com.android.support.test:rules:0.2')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.1')
}
强制使用一种版本 可以看到,原本对hamcrest-core 1.1的依赖,全部变成了1.3。
\--- com.android.support.test.espresso:espresso-core:2.1
+--- com.android.support.test:rules:0.2 (*)
+--- com.squareup:javawriter:2.1.1
+--- org.hamcrest:hamcrest-integration:1.1
| \--- org.hamcrest:hamcrest-core:1.1 -> 1.3
+--- com.android.support.test.espresso:espresso-idling-resource:2.1
+--- org.hamcrest:hamcrest-library:1.1
| \--- org.hamcrest:hamcrest-core:1.1 -> 1.3
+--- javax.inject:javax.inject:1
+--- com.google.code.findbugs:jsr305:2.0.1
+--- com.android.support.test:runner:0.2 (*)
+--- javax.annotation:javax.annotation-api:1.2
\--- org.hamcrest:hamcrest-core:1.1 -> 1.3
Exclude可以设置不编译指定的模块
configurations {
all*.exclude group: 'org.hamcrest', module: 'hamcrest-core'
}
dependencies {
androidTestCompile('com.android.support.test:runner:0.2')
androidTestCompile('com.android.support.test:rules:0.2')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.1')
}
单独使用group或module参数
exclude后的参数有group和module,可以分别单独使用,会排除所有匹配项。例如下面的脚本匹配了所有的group为’com.android.support.test’的模块。
dependencies {
androidTestCompile('com.android.support.test:runner:0.2')
androidTestCompile('com.android.support.test:rules:0.2')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.1') {
exclude group: 'org.hamcrest'
}
}
网友评论