Android Studio报错集锦(二)

这篇博客汇总了Android Studio常见的错误及解决方法,包括支持库无法解析、类报红、R8编译错误、控件初始化问题、内存溢出、依赖工程找不到、代码文件错乱、安装失败及release包无法打开等问题,并提供了详细的解决步骤。

 

Android Studio报错集锦(一)

Android Studio报错集锦(二)

Android Studio报错集锦(三)

Android Studio报错集锦(四)

 

十一:Could not resolve com.android.support:support-v4:19.1.+.

修改project的gradle,添加

maven { 
    url “https://maven.google.com” 
}

十二:导入的类报红

1. File -> Invalidate Caches/Restart -> Invalidate  and Restart

2.若1不行,则需要配置jre,具体参考:

配置Android Studio内置jre的环境变量

Android Studio(AS)内置jre进行环境配置、com.android.support:design:26.1.0

十三:app:transformClassesAndResourcesWithR8ForRelease

在项目中的gradle.properties文件中添加如下代码

org.gradle.daemon=true
org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
org.gradle.parallel=true
org.gradle.configureondemand=true

十四:Android Studio中app出现红叉:

    1. 若报错:No IDEA annotations attached to the JDK 1.8

        完美解决 No IDEA annotations attached to the JDK 1.8

    2. 若无上述错误,点击红叉,选择Edit configurations,最下方有提示
        或者参考:
        Android Studio APP红叉如何解决           

        Android Studio “Sync project with Gradle Files”按钮消失问题

十五:Attempt to invoke virtual method 'void android.widget.TextView.setVisibility(int)' on a null object reference
 首先要确认控件的位置,看控件是否在Activity的子界面中,若在,则要在加载子界面布局的位置初始化该控件。

十六:java.lang.OutOfMemoryError: Failed to allocate a 20971532 byte allocation with 4194304 free bytes and 7MB until OOM

需要在清单文件的application中加上下面两行代码:

android:largeHeap="true"
android:hardwareAccelerated="false"

<application
        android:name=".im.ImApplication"
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:largeHeap="true"
        android:hardwareAccelerated="false" 
        android:theme="@style/AppTheme"
        android:largeHeap="true"
        android:hardwareAccelerated="false">

十七:Error:Project with path 'XXXX' could not be found

配置文件setting.gradle里少了依赖工程的配置信息,添加以后rebuild peoject ,然后就OK了!

十八:AS代码、文件错乱

1.清除缓存重启AS: File ->  Invalidate Cahes/ Restart

2.删除项目路径下的 .gradle .idea 文件, 以及 app目录下的build文件,然后重新编译

3.清除build缓存 Clean 后 Rebuild一下

4.找到C盘/用户目录/.AndroidStudio版本号(如.AndroidStudio3.4)/system/cache文件夹,关闭studio后将其删除

十九:OPPO手机 "安装失败:安装包异常"

gradle.properties中添加android.injected.testOnly = false
若Demo无限闪退,解决方案: setting->instant run 中 关掉instant run

OPPO R11S 手机 Androidstudio直接运行安装apk时提示安装包异常

二十:release包安装后无法正常打开

debug包正常,release包无法打开,此时要考虑Gradle版本和Gradle插件的版本是否对应。

参考:Android应用闪退异常java.lang.RuntimeException: Unable to instantiate application

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值