1、问题:Android Studio3.0以后,在项目编译的时候发现Gradle中报错了,错误如下,

Cannot set the value of read-only property 'outputFile' for ApkVariantOutputImpl_Decorated

原因:3.0里面批量修改APK名字的配置有变化

解决方法:可参考:Cannot set the value of read-only property 'outputFile' for ApkVariantOutputImpl_Decorated_uu00soldier的博客

2、问题:AndroidStudio3.0 Unable to resolve dependency for ':app@betaUnitTest/compileClasspath': Could not

原因1:app的buildTypes 和依赖library中gradle的buildTypes设置的不一样,library中缺少debug

app中:
buildTypes {
        debug {
                ....
        }
        release {
                ....
        }
    }
library中:
 buildTypes {
        release {
                ....
        }
    }

解决方法:可参考:升级AndroidStudio3.0 Unable to resolve dependency for ':app@betaUnitTest/compileClasspath': Could not_你的小码哥哥的博客

原因2:我遇到的是项目的build.gradle里repositories缺少google()

解决办法2:

项目中build.gradle有这句话么?别切google()和jcenter()都不能少
repositories {
        google()
        jcenter()
    }

3、问题:微信开放平台SDK的Demo运行时报错:Unable to resolve dependency for ':app@debug/compileClasspath': Could not download wechat-sdk-android-with-mta.jar (com.tencent.mm.opensdk:wechat-sdk-android-with-mta:5.1.6): No cached version available for offline modess

原因:gradle设置为了Offline模式

解决方法:gradle的Offline work不选中。如下图,

android style编译报错 android studio无法编译_编译

4、问题: 找不到符号 符号:   方法 checkSelfPermission(BaseActivity,String) 位置: 类 ContextCompat

原因:这个方法是为了解决Android6.0以上的运行时权限问题,这个错误是因为libs下存在android-suport-v4.jar包,和build.gradle中引入的v4包冲突了,所以会产生这上面的这种错误

解决方法:可参考,友盟集成中“找不到符号”问题的解决_「 

5 Caused by: java.lang.RuntimeException: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex

原因:依赖library重复导致

解决方法:可参考,Unable to merge dex,专治Android Studio各种抽风!_ 

6、问题:Warning: there were * unresolved references to classes or interfaces.

原因:代码warn 导致

解决方法:在proguard-rules.pro这个文件了加了一行

-ignorewarnings

7、问题:Android 打包时出现 java.lang.OutOfMemoryError: GC overhead limit exceeded 的解决办法

原因:内存溢出

解决方法:在graldr中添加如下信息即可:

android {
      dexOptions {
            incremental true
            javaMaxHeapSize "4g"
        }

8、问题:Unable to load class 'org.gradle.api.internal.component.Usage'

原因:这是由于插件兼容问题导致的错误

解决方法:如果有com.novoda:bintray-release请把版本修改为0.5.0,如下图

android style编译报错 android studio无法编译_编译_02

9、问题:集成友盟分享(UShare),新浪微博出现崩溃,报错

java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.xuetangx.mobile-2/base.apk", zip file "/data/app/
...
/lib/arm64-v8a, /vendor/lib64, /system/lib64]]] couldn't find "libweibosdkcore.so"
 at java.lang.Runtime.loadLibrary(Runtime.java:367)
 at java.lang.System.loadLibrary(System.java:1076)

原因:其实有许多问题认真分析日志都可以看出来,入这个可以看到couldn't find "libweibosdkcore.so"。虽然你也有但是我们看到程序实在arm64-v8a中找的,而你的jniLib中没有,arm64-v8a是其他module有,所以不同意导致寻找不到

解决方法:统一不同module种CPU架构对应一个ABI:armeabi,armeabi-v7a,x86,mips,arm64- v8a,mips64,x86_64。如都是armeabi或armeabi-v7a

10、问题:retrofit 2.0 代码混淆后返回空数据

解决方法:使Entity数据不做混淆,如下图

android style编译报错 android studio无法编译_编译_03

11、问题:Failed to resolve: com.github.franmontiel:PersistentCookieJar:v1.0.1

解决方法:project的gradle中加入   maven { url "https://jitpack.io" },如下

allprojects {
    repositories {
        ...
        maven { url "https://jitpack.io" }
    }
}

12、问题:Could not find manifest-merger.jar (com.android.tools.build:manifest-merger:26.0.1

解决方法:在项目的build.gradle文件中使google()的位置在jcenter()的前面,如下

buildscript {
    repositories {
        maven {
            url "https://maven.google.com"
        }
        google()
        jcenter()

    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'
    }
}

// Allow plugins to declare Maven dependencies via build-extras.gradle.
allprojects {
    repositories {
        google()
        jcenter()
        mavenCentral()
    }
}

13、问题:Unexpected scopes found in folder '/Users/gaolei/gaolei/Android/Project/ppzc_app_android/ICarsclub/build/intermediates/transforms/AspectTransform/debug'. Required: SUB_PROJECTS. Found: EXTERNAL_LIBRARIES, PROJECT, SUB_PROJECTS

解决方式:去掉InstantRun,如下图

android style编译报错 android studio无法编译_错误_04

14、问题:No toolchains found in the NDK toolchains folder for ABI with prefix

解决方法:新版本的NDK与3.0及以前旧版的Android Gradle plugin插件不兼容,其实解决方法很简单,就是修改build.gradle中的红字部分,改为3.1以上版本即可,如下

dependencies {
    classpath 'com.android.tools.build:gradle:3.2.0'

    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
}

15、问题:com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex

解决方法:

步骤一:在app: build.gradle中添加multidex配置

android {
    defaultConfig {
	    ...
        multiDexEnabled true
    }
    dexOptions {
        incremental true
    }
}
dependencies {
    ...
    compile 'com.android.support:multidex:1.0.3'
}

步骤二:继承MultiDexApplication 或者在Application的attachBaseContext方法中加入

MultiDex.install(this);

16、问题:项目依赖的sdk版本从26升级到28后报错,java.util.concurrent.ExecutionException: com.android.builder.internal.aapt.v2.Aapt2Exception: Android resource compilation failed

解决方法:app默认的依赖不全导致,可以把运行成功的app的默认依赖拷贝过来,如下

implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support:design:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

17、问题:Execution failed for task ':app:mergeDebugResources'.

解决方法:由于logcat或者build没有给出具体详细的错误信息,无法轻易找出问题。因为和resource有关可使用命令:gradlew compileDebugSources --stacktrace -info。这样就会有详细的错误信息。其它错误信息可使用

'compileDebugAidl',
'compileDebugAndroidTestAidl',
'compileDebugAndroidTestJavaWithJavac',
'compileDebugAndroidTestNdk',
'compileDebugAndroidTestRenderscript',
'compileDebugAndroidTestShaders',
'compileDebugAndroidTestSources',
'compileDebugJavaWithJavac',
'compileDebugNdk',
'compileDebugRenderscript',
'compileDebugShaders',
'compileDebugSources',
'compileDebugUnitTestJavaWithJavac',
'compileDebugUnitTestSources'.

18、问题: Supertypes of the following classes cannot be resolved. Please make sure you have the required dependencies in the classpath:

解决方法:把library模块的依赖包implementation改为api,因为implementation依赖的包只能在本模块使用,api依赖的包可供其它模块使用

implementation 'com.squareup.okhttp3:okhttp:3.14.2'
改为
api 'com.squareup.okhttp3:okhttp:3.14.2'

19、问题:Duplicate class android.support.v4...

解决方法:是因为项目中依赖的第三方library中由多个library有依赖android.support.v4导致重复,引起的错误。

可通过命令查看依赖:./gradlew -q sample:dependencies --configuration debugCompileClasspath

20、问题:倒入一个项目时,报错> Could not download gradle.jar (com.android.tools.build:gradle:3.5.3): No c。  Could not download baseLibrary.jar (com.android.databinding:baseLibrary:3.5.

解决方法:修改gradle版本为你已经编译成功项目的版本。有两个地方需要修改

a、 build.gradle文件中的

classpath 'com.android.tools.build:gradle:3.5.0

b、gradlew/wrapper/gradle-wrapper.properties文件中的

distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.1-all.zip

21、问题:项目可以编译过,但是一片红找不到类

解决方法:1、重启AndroidStudio 2、如果重启不行就清AndroidStudio缓存,步骤File --> Invalidate Caches/Restart

22、问题:同步gradle时报错:A problem occurred configuring root project 'RecyclerView'.
> Could not resolve all artifacts for configuration ':classpath'.
   > Could not find com.android.tools.build:gradle:3.5.0.

解决方法:项目gradle中的 repositories 增加google()

repositories {
        jcenter()
        google()
    }

23、问题:Gradle下载依赖库失败

解决方法:增加Gralde阿里云镜像

buildscript {
    repositories {
        maven { url 'https://maven.aliyun.com/repository/jcenter' }
        maven { url 'https://maven.aliyun.com/repository/google' }
        maven { url 'https://maven.aliyun.com/repository/central' }
        maven { url 'https://maven.aliyun.com/repository/gradle-plugin' }
        google()
        jcenter()
    }
    dependencies {
        classpath "com.android.tools.build:gradle:4.1.3"

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        maven { url 'https://maven.aliyun.com/repository/jcenter' }
        maven { url 'https://maven.aliyun.com/repository/google' }
        maven { url 'https://maven.aliyun.com/repository/central' }
        maven { url 'https://maven.aliyun.com/repository/gradle-plugin' }
        google()
        jcenter()
    }
}