• Android开发-Android Studio问题以及解决记录


    [Android开发] Android Studio问题以及解决记录

     

    http://blog.csdn.net/niubitianping/article/details/51400721

    1、真机运行报错Multi dex requires Build Tools 21.0.0 / Current: 19.1

    这里写图片描述

    解决:

    在项目 build.gradle 里面把classpath ‘com.android.tools.build:gradle:1.5.0’ 改为1.5.0 或者1.3.0

    2、导入第三方包运行报错:前言不允许有内容

    这里写图片描述

    解决

    一般是包的位置错误,请放到main目录下的libs 文件夹里面,再右键 add as library

    3、运行错误: finished with non-zero exit valule 2

    这里写图片描述

    1. 包冲突

    例如可能你v7支持包,v4支持包都有这个类,一编译就冲突了,或者你complie了包,然后又手动add as library了,或者重复add了,等等。 (反正我出现这个问题几乎都是包冲突)

    2. 其他错误

    这个一般会有错误提示,在编译的日志上面,例如图片不正确,看看是不是重新添加了图片,然后在Android studio 里面双击打开这个图片看看 是否能正常打开,打不开就重新保存一下格式(这个情况一般是出现在自己一个搞项目时候乱搞图片会出现的问题)

    4、编译错误 Gradle DSL method not found: ‘apt()’

    这里写图片描述

    解决

    1、在项目的gradle的dependencies里面添加

    classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'

    2、在你这个module的gradle里面的头部添加

    apply plugin: 'android-apt'

    重新编译解决

    5、Failed to resolve: org.hamcrest:hamcrest-core:1.3

    这里写图片描述

    解决:

    打开as 的Setting,gradle路径下的offline work 勾选,路径改为gradle解压之后的文件夹,gradle可以自己上网下载http://services.gradle.org/distributions

    6、打包时候报错 Error: Expected resource of type styleable [ResourceType]

    这里写图片描述

    一般位于这里:

    TypedArray ta = mContext.obtainStyledAttributes(attrs);
    boolean hasBottomLine = ta.getBoolean(0, false);
    boolean hasTopLine = ta.getBoolean(1, false);

    解决:

    在报错的这行代码的 方法体上面加@SuppressWarnings(“ResourceType”)

    @SuppressWarnings("ResourceType")
        public SystemBarTintManager(Activity activity) {
    
            Window win = activity.getWindow();
            ViewGroup decorViewGroup = (ViewGroup) win.getDecorView();
    
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
                // check theme attrs
                int[] attrs = {android.R.attr.windowTranslucentStatus,
                        android.R.attr.windowTranslucentNavigation};
                TypedArray a = activity.obtainStyledAttributes(attrs);
                try {
                    mStatusBarAvailable = a.getBoolean(0, false);
                    mNavBarAvailable = a.getBoolean(1, false);
                } finally {
                    a.recycle();
                }
                。。。。。。

    即可解决

    7、混淆后打包报错: java.io.IOException: The same input jar [D:Usersworkspace_studioTest5applibsxxxxxxx.jar] is specified twice

    这里写图片描述

    原因: 
    build.gradle文件配置了 
    dependencies { compile fileTree(include: ‘*.jar’, dir: ‘libs’)}

    里面已经添加过jar包,混淆文件proguard-rules.pro里面又加了句-libraryjars libs/.jar,将-libraryjars libs/.jar

    解决:

    proguard-rules.pro中的 -libraryjars libs/*.jar ,前面用#号注释或者直接删掉即可。

    8、打包时候报错Suspicious method call; should probably call “layout” rather than”onLayout”:

    Suspicious method call; should probably call "layout
    " rather than"onLayout"

    解决:

    在调用onLayout的方法 上加

    @SuppressLint("WrongCall")
    • 1

    9、编译的时候报错:Error running app:Instant Run requires ‘Tools|Android|Enable ADB integration’ to be enabled

    这里写图片描述

    解决:

    开启adb, 菜单Tools—-Android——Enable ADB Integration

    这里写图片描述

    10、R 文件报错,无法取消引用int


    这里写图片描述

    原因:

    自动导入了其他的R文件包,例如百度地图的R文件包

    解决:

    把其他R文件的包删掉,添加自己的包名的R文件。

    11、Gradle sync failed: Unable to load class ‘org.gradle.internal.logging.LoggingManagerInternal’

    gradle版本和android-maven-gradle-plugin 版本不协调

    解决: 
    如果你的gradle用的是2.1.2 ,你要把android-maven-gradle-plugin改为1.3

    这里写图片描述

    11、导入ADT项目报错There are unrecoverable errors which must be corrected first

    这里写图片描述

    看android Studio的信息,说appcompat_v7_12 could not found,所以就是这个问题了。

    把eclipse的project根目录project.properties里面的android.library.reference.1=../appcompat_v7删掉,再重新导入AndroidStudio就行了

    12、打印的Log显示不全

    log输出进行了字符的限制为4000个,解决方法是写一个类采用分段的方法输出log

        public static void printAll(String str){
            if (str.length() > 4000) {
                Log.v(TAG, "sb.length = " + str.length());
                int chunkCount = str.length() / 4000;     // integer division
                for (int i = 0; i <= chunkCount; i++) {
                    int max = 4000 * (i + 1);
                    if (max >= str.length()) {
                        Log.v(TAG, "chunk " + i + " of " + chunkCount + ":" + str.substring(4000 * i));
                    } else {
                        Log.v(TAG, "chunk " + i + " of " + chunkCount + ":" + str.substring(4000 * i, max));
                    }
                }
            } else {
                Log.v(TAG, str);
            }
        }

    13、导入微信demo错误:Error:java.lang.RuntimeException:Some file crunching failed,see logs for details

    这里写图片描述

    在build.gradle的andoid里面添加

    aaptOptions.cruncherEnabled = false
    aaptOptions.useNewCruncher = false

    14、断开手机连接,远程主机强迫关闭了一个现有的连接

    这里写图片描述
    1. miui系统关闭usb安装管理,运行安装未知来源。 
    2. 重写拔插手机 
    3. 电脑换个插口 
    4. 换根数据线

    15、Failed to open zip file.

    Gradle’s dependency cache may be corrupt(this sometimes ocurs after a network connection timeout.) 
    这里写图片描述

    我是搞了svn才出现的问题。

    解决方法: 
    设置gradle

    1. 设置本地gradle

    把gradle压缩包解压出来,放随便一个盘,在as里面设置 
    这里写图片描述

    2. 搭建本地的gradle服务器。

    Windows安装iis,然后把gradle的压缩包放iis目录里面,然后在 项目根目录gradlewrappergradle-wrapper.properties,修改最后的为distributionUrl=http://localhost/xxxxx.zip ,重新构建就o了

    例如我的就是

    distributionUrl=http://localhost/gradle-2.14.1-all.zip

    这里写图片描述

    16、No cached version of com.android.tools.build:gradle:2.2.3 available for offl

    这里写图片描述

    更新了AS之后出现的问题,更新AS,对应的gradle也得更新了,但是如果你使用的是之前的离线的GRadle就会出现这样的问题了。

    解决方法

    File – Setting – Gradle – 取消勾选Offine work,选择回默认的gradle wrapper

    这里写图片描述

    17、Error converting bytecode to dex:Cause:com.android.dex.DexEcception:Multiple dex files define….

    这里写图片描述

    原因1: 重复导包 
    原因2: buildToolsVersion和compileSdkVersion的版本不对

    解决: 对应上面的原因修改即可,本人的原因是因为第二个。

    18、Error:org.gradle.api.internal.tasks.DefaultTaskInputs$TaskInputUnionFileCollection cannot be cast to org.gradle.api.internal.file.collections.DefaultConfigurableFileCollection Possible causes for this unexpected error include:Gradle’s dependency…

    这里写图片描述

    原因: gradle的版本不对。

    解决: 把project的build.gralde的版本改为你的AndroidStudio的版本号,例如我是2.3.0版本的,就得把gradle版本改为2.3.0,然后重新sync即可。看图 
    这里写图片描述

    然后重新构建,出现下面的问题,就点第一个update即可。 
    这里写图片描述

    19、Error while Installing APK,安装app失败,远程主机强迫关闭了一个现有的链接

    这里写图片描述

    解决: 打开任务管理器,把adb进程给关掉就行了

  • 相关阅读:
    微服务架构
    微服务架构
    Java语言编程
    Java语言编程
    Java语言编程
    《自己动手写云盘》 – 确立需求
    树上差分
    线性基
    BM(Berlekamp-Massey)算法
    FFT/FWT
  • 原文地址:https://www.cnblogs.com/it-tsz/p/10753123.html
Copyright © 2020-2023  润新知