Android开发错误——Android Studio中遇到过的错误问题与解决方案汇总

Posted 许英俊潇洒

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Android开发错误——Android Studio中遇到过的错误问题与解决方案汇总相关的知识,希望对你有一定的参考价值。

(1)编译时发生

Error:(25, 0) Gradle DSL method not found: 'compile()'
Possible causes:<ul><li>The project 'AP' may be using a version of Gradle that does not contain the method.
<a href="openGradleSettings">Gradle settings</a></li><li>The build file may be missing a Gradle plugin.
<a href="apply.gradle.plugin">Apply Gradle plugin</a></li>


解决方法:

1、在最外层的Gradle中,删除如下的语句

dependencies 
    compile files('libs/xUtils-2.6.14.jar')


(2)编译时发生

Error:(25, 0) Gradle DSL method not found: 'android()'
Possible causes:<ul><li>The project 'AP' may be using a version of Gradle that does not contain the method.
<a href="openGradleSettings">Gradle settings</a></li><li>The build file may be missing a Gradle plugin.
<a href="apply.gradle.plugin">Apply Gradle plugin</a></li>


解决方法:

1、在最外层的Gradle中,删除如下的语句

android 
    compileSdkVersion 23
    buildToolsVersion '23.0.2'


(3)编译时发生

Error:(1, 0) Your project path contains non-ASCII characters. This will most likely cause the build to fail on Windows. Please move your project to a different directory. See http://b.android.com/95744 for details. This warning can be disabled by using the command line flag -Dcom.android.build.gradle.overridePathCheck=true, or adding the line com.android.build.gradle.overridePathCheck=true' to gradle.properties file in the project directory.
<a href="openFile:D:\\workspacebackup\\我的框架\\AP\\app\\build.gradle">Open File</a>


解决方法:

1、你的项目中存在中文命名,将项目中对应的中文命名改为英文即可


(4)编译时发生

Error:Execution failed for task ':app:mergeDebugResources'.
> D:\\workspace5\\Boke\\app\\src\\main\\res\\drawable\\custom_Animation_progress_bar.xml: Error: 'A' is not a valid file-based resource name character: File-based resource names must contain only lowercase a-z, 0-9, or underscore


解决方法:

1、你的项目中res\\drawable下存在大写字母,将项目中对应的大写字母改为小写字母即可


(5)在Aidl文件进行编译时发生

Error:Execution failed for task ':app:compileDebugAidl'.
> java.lang.RuntimeException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'E:\\Eclipse\\android-studio-sdk\\android-sdk-windows\\build-tools\\23.0.2\\aidl.exe'' finished with non-zero exit value 1


解决方法:

1、项目的编译版本和编译工具的版本不一致,右键项目 open Moudle Setting -> app -> 修改Compile Sdk Version 和Build Tools Version 版本一致

2、可能是你的复制进来的Aidl文件的包名没有修改成当前的包名


(6)在复制权限内容,进行编译时发生

Error:Execution failed for task ':yuyin:processDebugResources'.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'E:\\Eclipse\\android-studio-sdk\\android-sdk-windows\\build-tools\\23.0.2\\aapt.exe'' finished with non-zero exit value 1

解决方法:

1、就是xml 可能出现无法识别的资源文件错误, 就是资源文件 里面出错了

2、有时候在uses-permission中多了个空格也会报这个错误


(7)run程序时发生

Error running app: Instant Run requires 'Tools | Android | Enable ADB integration' to be enabled.


解决方法:

1、勾选中下图选项即可



(8)在配置NDK后编译时发生

Error:Execution failed for task ':app:compileDebugNdk'.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'E:\\Eclipse\\android-studio-sdk\\android-sdk-windows\\ndk-bundle\\ndk-build.cmd'' finished with non-zero exit value 2


解决方法:

1、编译NDK时最好不要使用SDKManager里下载的ndk-bundle,否则会报这些错误

2、官网下载NDK开发包,r9、r10系列,然后替换掉久的ndk就可以了


(9)在Android Studio->run的时候发生

Unable to create Debug Bridge: Unable to start adb server: error: could not install *smartsocket* listener: cannot bind to 127.0.0.1:5037: 通常每个套接字地址(协议/网络地址/端口)只允许使用一次。 (10048)
could not read ok from ADB Server
* failed to start daemon *
error: cannot connect to daemon
'E:\\Eclipse\\android-studio-sdk\\android-sdk-windows\\platform-tools\\adb.exe,start-server' failed -- run manually if necessary


解决方法:

1、网上的方案,亲测不是这个问题

根据提示查看adb的端口号5037被谁占用,通过 netstat -aon|findstr “5037” 找出相应的pid号,再通过任务管理器找到相应pid号的进程,然后将其结束,最后重启adb

2、将原本选择的默认adb换成我们自己的sdk里面的adb,亲测成功了


(10)创建了两个Module,其中一个Module依赖另一个Module而导致了出现该问题,如果在Android Studio中,有ModuleA和ModuleB,我们希望ModuleA依赖ModuleB,运行时候可能会出现该问题

Error:Dependency Boke:zXingProj:unspecified on project app3 resolves to an APK archive which is not supported as a compilation dependency. File: D:\\workspace5\\Boke\\zXingProj\\build\\outputs\\apk\\zXingProj-release-unsigned.apk


解决方法:

1、查看被依赖的ModuleB的build.gradle,里面可以看到

apply plugin: 'com.android.application'  
将这一句改为即可
apply plugin: 'com.android.library'  
接着会出现另一个错误
Error:Library projects cannot set applicationId. applicationId is set to 'com.dtr.zxing' in default config.

解决方法:

1、需要将builde.gradle — android — defaultConfig中的applicationId删除


(11)这个问题是我在修改Bmob的最新jar包的时候发生的错误,从3.4.6换到3.5.0时,编译出错

Error:Execution failed for task ':app:transformClassesWithDexForRelease'. > com.android.build.api.tr


解决方案:

1、jar包冲突(finished with non-zero exit value 2) 
主要表现为编译后出现 finished with non-zero exit value 2错误,原因是jar包冲突,导致的原因可能是在dependencies中使用compile files()导入一次jar包,然后有其它jar的引入方式使用compile’com.xxx’方式,正好又引用了这个jar包,所以导致了重复引用jar包的冲突。最常见的是support-v4包的重复引用

(12)当在gradle导入第三方依赖(sweetalert)之后,编译出错

Error:Execution failed for task ':qq:processDebugManifest'.
> Manifest merger failed : Attribute application@icon value=(@mipmap/ic_launcher) from AndroidManifest.xml:45:9-43
	is also present at [com.pnikosis:materialish-progress:1.0] AndroidManifest.xml:13:9-45 value=(@drawable/ic_launcher).
	Suggestion: add 'tools:replace="android:icon"' to <application> element at AndroidManifest.xml:42:5-122:19 to override.


解决方案:

1、由于导入的第三方依赖也使用我们application的icon值的属性,具体修改步骤如下图,加上下面圈起来的语句



(13)Git Push 提交到Github上发生错误

$ git push origin master
To https://github.com/AndroidHensen/NewsTemplate.git
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'https://github.com/AndroidHensen/NewsTemplate.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.


解决方案:

1、出现的主要原因是,本地没有update到最新版本的项目(git上有README.md文件没下载下来)

2、先进行代码合并,git pull --rebase origin master,再进行代码提交,git push -f origin master


(14)升级完Android Studio2.3后,打包release出现的错误

Error:Execution failed for task ':qq:lintVitalRelease'.
> Lint found fatal errors while assembling a release target.
To proceed, either fix the issues identified by lint, or modify your build script as follows:
...
android 
    lintOptions 
        checkReleaseBuilds false
        // Or, if you prefer, you can continue to check for errors in release builds,
        // but continue the build even when errors are found:
        abortOnError false
    

...


解决方法:

在app的build.gradle中添加如下代码,重新Generate Signed APK即可

android
    lintOptions 
        checkReleaseBuilds false
        abortOnError false
    





以上是关于Android开发错误——Android Studio中遇到过的错误问题与解决方案汇总的主要内容,如果未能解决你的问题,请参考以下文章

android createTempFile 抛出权限被拒绝?

Android eclipse常见错误开发总结

android 开发问题集,android问题总结,android错误解决收集

Android NDK开发Crash错误定位

Android应用开发中出现appcompat-v7错误

Android开发错误——Android Studio中遇到过的错误问题与解决方案汇总