zoukankan      html  css  js  c++  java
  • Android studio2.3.3升级3.1.2坑

    原文:https://blog.csdn.net/qq_26361871/article/details/80255141

    1.grade配置Error: Could not find com.android.tools.build:gradle:2.2.1.
    解决方法与Maven仓库有点像:进入
    D:softwareandroidandroid-studio-ide-145.3276617-windowsandroid-studiogradlem2repositorycomandroid oolsuildgradle
     
    将项目中的build.gradle文件中
    dependencies { classpath 'com.android.tools.build:gradle:2.2.1'}
     
    改为
    dependencies { classpath 'com.android.tools.build:gradle:3.1.2'}
    2.All flavors must now belong to a named flavor dimension.
    在module下的build.gradle中添加一行代码即可解决:
    android{ ... flavorDimensions "versionCode" ...}
    3.升级到Android Studio 3.1,重新构建项目时报错,主要错误为:
    The SourceSet 'instrumentTest' is not recognized by the Android Gradle Plugin. Perhaps you misspelled something?
    instrumentTest已被废弃,新的Gradle插件已经不支持。instrumentTest需要修改为androidTest。
    修改后,sourceSets相关内容类似:
    android { buildToolsVersion "27.0.3" compileSdkVersion 24 sourceSets { main { manifest.srcFile 'AndroidManifest.xml' java.srcDirs = ['src'] aidl.srcDirs = ['src'] renderscript.srcDirs = ['src'] res.srcDirs = ['res'] assets.srcDirs = ['assets'] jniLibs.srcDirs = ['libs'] } androidTest.setRoot('tests') }}
    4. AAPT2 编译报错 AAPT2 error
    报错
    Error:java.util.concurrent.ExecutionException: com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details
    解决:在gradle.properties中关闭APPT2 编译
    1
    android.enableAapt2=false
    注:如果是eclipse转到as上的项目,可能没有gradle.properties文件,请在项目根目录中手动创建
    5.升级完Android Stadio 3.1以后
    将所有的compile变为implementation 后,clean和rebuild都没有发现错误,唯独在run的时候出现了以下错误:
    原因及解决办法
    • 原因:按照android stadio 3.1的要求,需要把gradle版本升级为 4.4及以上,但是gradle 4.4及以上要求将依赖api的compile换成implementation。而implementation声明的依赖没办法传递到module以外,即该module 以外module没办法引用到implementation声明的api。
    即:module A implementation libA,而 moduleB implementation module A,那么module B 引导 libA 中的api,不然在build的时候会报org.gradle.api.internal.tasks.compile.CompilationFailedException。
    • 解决办法:将compile 替换为 api即可,也就是如果有外部引用,则换成:api,剩下的换成:implementation。
    示例:
    dependencies { api fileTree(dir: 'libs', include: ['*.jar']) testImplementation 'junit:junit:4.12' api 'com.android.support:support-v4:26.1.0' api 'com.android.support:appcompat-v7:26.1.0' api 'com.google.code.gson:gson:2.8.2' api 'com.j256.ormlite:ormlite-core:4.48' api 'com.j256.ormlite:ormlite-android:4.48'
     
    ps:解决办法:
    Android 6.0(api 23)已经不支持HttpClient了,在build.gradle中 加入 useLibrary 'org.apache.http.legacy'就可以了,如图:
    Error:(633, 16) 错误: 找不到符号 符号: 方法 sqrt(float) 位置: 类 FloatMath
    解决方案
    原因是Android6.0不支持FloatMath.sin()了,主要有两个方法可以解决。
    方法一:
    用23一下的SDK版本进行编译。将gradle.build文件里(包括project的gradle.build和module的gradle.build)的compileSdkVersion设为23以下。
    方法二:
    将上面报错的地方,即 用Math类替换FloatMath类,Math.sin();
    方法三 :
    (float)Math.sqrt 替换 FloatMath.sqrt
  • 相关阅读:
    Security and Cryptography in Python
    Security and Cryptography in Python
    Security and Cryptography in Python
    Security and Cryptography in Python
    Security and Cryptography in Python
    Security and Cryptography in Python
    Security and Cryptography in Python
    微信小程序TodoList
    C语言88案例-找出数列中的最大值和最小值
    C语言88案例-使用指针的指针输出字符串
  • 原文地址:https://www.cnblogs.com/tc310/p/9179486.html
Copyright © 2011-2022 走看看