配环境这玩意儿真是考验耐力和碰运气啊!!!!
导入一个已有的gradle项目
一开始提示 Error:failed to find Build Tools revision 21.1.1
来回改project structure里面的配置,指定不同的SDK,反正安装android studio默认的sdk不能使用
Error:(11, 0) Gradle DSL method not found: 'android()'
Possible causes:
the project '' may be using a version of Gradle that does not contain the method.
The build file may be missing a Gradle plugin.
大概还是指定的编译版本不对
尝试改一下project structure里面的配置,发现子module的配置没有,只是外面一级目录,改成指定的SDK build tools
各种重新导入-删除-重新导入-卸载ing
(在android studio中可能由于误操作,删除硬盘的源文件,所以最好先备份)
终于有一次导入后,还是提示 Error:failed to find Build Tools revision 21.1.1
但是,这次打开project structure出现了很多modules,这才是我要的方式嘛,挨个配置它们的
编译中错误:
UNEXPECTED TOP-LEVEL ERROR:
java.lang.OutOfMemoryError: Java heap space
at java.util.Arrays.copyOfRange(Arrays.java:3658)
at java.lang.String.
at java.lang.StringBuilder.toString(StringBuilder.java:407)
at com.android.dx.rop.type.Type.asUninitialized(Type.java:836)
at com.android.dx.cf.code.ValueAwareMachine.run(ValueAwareMachine.java:172)
at com.android.dx.cf.code.RopperMachine.run(RopperMachine.java:304)
at com.android.dx.cf.code.Simulator$SimVisitor.visitConstant(Simulator.java:691)
at com.android.dx.cf.code.BytecodeArray.parseInstruction(BytecodeArray.java:764)
at com.android.dx.cf.code.Simulator.simulate(Simulator.java:94)
at com.android.dx.cf.code.Ropper.processBlock(Ropper.java:787)
at com.android.dx.cf.code.Ropper.doit(Ropper.java:742)
at com.android.dx.cf.code.Ropper.convert(Ropper.java:349)
at com.android.dx.dex.cf.CfTranslator.processMethods(CfTranslator.java:280)
at com.android.dx.dex.cf.CfTranslator.translate0(CfTranslator.java:137)
at com.android.dx.dex.cf.CfTranslator.translate(CfTranslator.java:93)
at com.android.dx.command.dexer.Main.processClass(Main.java:729)
at com.android.dx.command.dexer.Main.processFileBytes(Main.java:673)
at com.android.dx.command.dexer.Main.access$300(Main.java:83)
at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:602)
at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:284)
at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:166)
at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144)
at com.android.dx.command.dexer.Main.processOne(Main.java:632)
at com.android.dx.command.dexer.Main.processAllFiles(Main.java:505)
at com.android.dx.command.dexer.Main.runMultiDex(Main.java:334)
at com.android.dx.command.dexer.Main.run(Main.java:244)
at com.android.dx.command.dexer.Main.main(Main.java:215)
at com.android.dx.command.Main.main(Main.java:106)
在项目配置的build.gradle文件里面,有一段
dexOptions { javaMaxHeapSize "2g" }
有的版本android studio需要注释,有的需要保留
=====================以下为转载其他地方写的编译等出错问题================
原文:http://www.codeceo.com/article/android-studio-problems.html
Error:(26, 9) Attribute application@icon value=(@drawable/logo) from AndroidManifest.xml:26:9
Error:(28, 9) Attribute application@theme value=(@style/ThemeActionBar) from AndroidManifest.xml:28:9
is also present at XXXX-trunk:XXXXLib:unspecified:15:9 value=(@style/AppTheme)
Suggestion: add ‘tools:replace=”android:theme”‘ to
Error:Execution failed for task ‘:XXXX:processDebugManifest’.
> Manifest merger failed with multiple errors, see logs
原因:
AS的Gradle插件默认会启用Manifest Merger Tool,若Library项目中也定义了与主项目相同的属性(例如默认生成的android:icon和android:theme),则此时会合并失败,并报上面的错误。
解决方法有以下2种:
方法1:在Manifest.xml的application标签下添加tools:replace=”android:icon, android:theme”(多个属性用,隔开,并且记住在manifest根标签上加入xmlns:tools=”http://schemas.android.com/tools”,否则会找不到namespace哦)
方法2:在build.gradle根标签上加上useOldManifestMerger true (懒人方法)
参考官方介绍:
http://tools.android.com/tech-docs/new-build-system/user-guide/manifest-merger
Library Project里面的BuildConfig.DEBUG永远都是false。这是Android Studio的一个已知问题,某Google的攻城狮说,Library projects目前只会生成release的包。
Issue 52962: https://code.google.com/p/android/issues/detail?id=52962
解决方法:(某Google的攻城狮推荐的方法)
Workaround: instaed of BuildConfig.DEBUG create another boolean variable at lib-project’s e.g. BuildConfig.RELEASE and link it with application’s buildType.
https://gist.github.com/almozavr/d59e770d2a6386061fcb
参考stackoverflow上的这篇帖:
http://stackoverflow.com/questions/20176284/buildconfig-debug-always-false-when-building-library-projects-with-gradle
每次保存的时候,每行多余的空格和TAB会被自动删除(例如结尾、空行的多余空格或TAB)
特别是每次准备提交SVN,Review代码时候你就蛋疼了,显示一堆不相关的更改,看的眼花。
解决方法:
Settings->IDE Settings->Editor->Other->Strip trailing spaces on Save->None
编译的时候,报:Failure [INSTALL_FAILED_OLDER_SDK]。一般是系统自动帮你设置了compileSdkVersion
解决方法:
修改build.gradle下的compileSdkVersion ‘android-L’为compileSdkVersion 19(或者你本机已有的SDK即可)