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

news/2024/7/4 13:04:50

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'
   
  • 1

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

apply plugin: 'android-apt'
   
  • 1

重新编译解决

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);
   
  • 1
  • 2
  • 3

解决:

在报错的这行代码的 方法体上面加@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();
            }
            。。。。。。
   
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18

即可解决

7、混淆后打包报错: java.io.IOException: The same input jar [D:\Users\workspace_studio\Test5\app\libs\xxxxxxx.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"
   
  • 1
  • 2

解决:

在调用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);
        }
    }
   
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16

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

这里写图片描述

在build.gradle的andoid里面添加

aaptOptions.cruncherEnabled = false
aaptOptions.useNewCruncher = false
   
  • 1
  • 2

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目录里面,然后在 项目根目录\gradle\wrapper\gradle-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进程给关掉就行了


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


http://www.niftyadmin.cn/n/667910.html

相关文章

ZEOSDBO控件的安装及使用方法

步骤&#xff1a; 1:下载最新版的ZEOSDBO&#xff0c;官网:http://sourceforge.net/projects/zeoslib/ 2:解压文件到文件安装目录下&#xff1a;C:\Program Files\Embarcadero\RAD Studio\9.0\ZEOSDBO-7.0.4 3.运行delphi xe2&#xff0c;.然后从“File”菜单中选择“Open Proj…

date iso 8610

$day date_iso8601(REQUEST_TIME);dpm($day);// 2015-08-20T14:35:5608:00转载于:https://www.cnblogs.com/qinqiu/p/4745415.html

帝国 listenews.php,帝国CMS获取当前自定义列表的listid

准备用帝国自定义列表功能做几个专题&#xff0c;但是发现没办法调用自定义列表的当前ID(数据库字段为listid)&#xff0c;在帝国论坛也没找到合适的答案。于是百度了一下&#xff0c;在这里找到了。不敢独食&#xff0c;马上发来和大家分享。这里需要修改底层文件functions.ph…

每辆车能坑6万元 揭开事故车翻新内幕

事故车不愁卖不出去&#xff01;‘整容’过的事故车&#xff0c;转手便可以赚数万元&#xff01;”说这话的是老卞&#xff0c;一位维修厂的工作人员&#xff0c;他每个月会给几辆准备销售的事故二手车进行全方位的“整容”。通过他&#xff0c;记者挖掘出了二手车中介公司和维…

Eclipse突然崩溃或电脑突然断电后,代码丢失找回

晚上遇见个奇葩的事&#xff0c;Eclipse正写着代码&#xff0c;电脑突然蓝屏&#xff0c;开机后Eclipse中打开的类文件中的代码丢失了&#xff0c;次奥&#xff0c;真尼玛吓尿了&#xff0c;不想这周的工作白费啊。 悲痛欲绝&#xff0c;突然右击发现了一个localhistory-->r…

buildConfigField boolean, LOG_DEBUG, true

buildConfigField "boolean", "LOG_DEBUG", "true"这个是我自定义的一个布尔值变量&#xff0c;它有什么用处呢&#xff1f;比如是程序中我可以通过BuildConfig.LOG_DEBUG 拿到这个变量&#xff0c;然后通过这个来书写线上环境的地址和测试环境的…

php 微信检测域名是否被封,检测域名是否已被微信封掉不能访问

微信营销中&#xff0c;经常出现域名被封&#xff0c;但是因不能及时了解情况从而浪费很多流量的情况。那么有没有办法可以实时检测域名是否已被微信封掉不能访问呢&#xff1f;今天我给大家分享一个专门用来解决这种情况的微信域名检测接口。微信域名检测api接口&#xff1a;使…