1. 强制设置gradle依赖版本号
android{
...
}
...
configurations.all {
//强制recyclerview版本号为1.1.0-beta03
resolutionStrategy.eachDependency { details ->
def requested = details.requested
if (requested.group == "androidx.recyclerview" && requested.name == 'recyclerview') {
details.useVersion('1.1.0-beta03')
}
}
}
...
2. 刷新依赖
gradle build --refresh-dependencies
3. AndroidStudio右上角的Gradle里不显示Task
问题如图,不显示Task,只显示依赖(图片上传失败)
解决方式:依次点击:File -> Settings -> Experimental -> 取消勾选 “Do not build Gradle task list during Gradle sync”保存设置再次同步项目
https://blog.csdn.net/TLuffy/article/details/113401090
4. Android Studio一直build model
可以将gradle文件中的 "jcenter()" 和 "mavenCentral()"全部注释掉,换成阿里的镜像,如下:
buildscript {
repositories {
//jcenter()
//mavenCentral()
maven{ url 'http://maven.aliyun.com/nexus/content/groups/public/'}
google()
}
dependencies {
...
}
}
allprojects {
repositories {
google()
//jcenter()
//mavenCentral()
maven{ url 'http://maven.aliyun.com/nexus/content/groups/public/'}
}
}
5.AndroidStudio编译时报OOM
可以将项目顶级目录下的gradle.properties
文件中的Xmx参数调大,意思是调大JVM允许分配的最大堆内存,具体如下:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.
# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
#org.gradle.jvmargs=-Xmx1536m -Dfile.encoding=UTF-8
#调大,换成4096
org.gradle.jvmargs=-Xmx4096m -Dfile.encoding=UTF-8
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
# AndroidX package structure to make it clearer which packages are bundled with the
# Android operating system, and which are packaged with your app's APK
# https://developer.android.com/topic/libraries/support-library/androidx-rn
android.useAndroidX=true
# Automatically convert third-party libraries to use AndroidX
android.enableJetifier=true
其中可调的参数有Xms
、Xms
等,可以参考该文章:Xms Xmx PermSize MaxPermSize 区别
网友评论