公司项目有导入10多个libray,还有涉及ndk,转Android studio时碰到不少问题。前后大概花费5个工作日,中间各种奇葩bug,各种编译出错,非常多还有没错误提示。一度想过放弃,如不是没有选择,可能真要放弃了。最后成功转型还是非常值得的。现记录下遇到的问题,给有须要的人。
1.
解决:
在manifest里面,某个activity下多写了一句intent-filter,里面没有内容,删了之后就没错误了。
2.
错误例如以下:
解决:
3.
File > Settings > Build, Execution, Deployment > Compiler
and see "Command-line-options" and check if anything is give. (In your case -x). If so remove it and click Apply and Ok. Now restart your android studio and try building
解决:
配置错误把这里的配置删掉
4.
> com.android.build.api.transform.TransformException: java.lang.RuntimeException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException:
Process ‘command ‘C:\Program Files\Java\jdk1.7.0_51\bin\java.exe‘‘ finished with non-zero exit value 1
解决:
电脑配置可能不够用,所以開始不断尝试改动占用内存相关的东西。并最终取得了进展。关键代码是build.gradle中的:
dexOptions {
javaMaxHeapSize "xx"
}
xx为合理的内存大小(如4g)。假设你也遇到了这样的问题,最好还是试试~
5.
Error:(24, 1) A problem occurred evaluating root project ‘MyApplication2‘.
> Could not find method dexOptions() for arguments [build_6h7x2ds382w4ozyuts7q05l4x$_run_closure3@2e96270a] on root project ‘MyApplication2‘.
解决:
不能写成一行
dexOptions { javaMaxHeapSize "xx" }
6.
7.
解决:
改成相相应的版本 compile‘com.android.support:appcompat-v7:19.+‘
8.
Error:Error: File path too long on Windows, keep below 240 characters : C:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\unspecified\res\drawable-xhdpi-v4\battle_navigation_button_signout_default.png
解决:
把文件甲路径缩短
9.
Error:Execution failed for task ‘:wonderDroid:processDebugAndroidTestManifest‘.
> java.lang.RuntimeException: Manifest merger failed : Attribute application@theme value=(@style/Theme.Sherlock) from [debug] AndroidManifest.xml:22:9-46
is also present at [branch_20151216_1.5.0_01_copy:emuUtils:unspecified] AndroidManifest.xml:15:9-40 value=(@style/AppTheme).
Suggestion: add ‘tools:replace="android:theme"‘ to <application> element at manifestMerger3943799027194821591.xml:7:5-9:19 to override.
解决方式:
在Manifest.xml的application标签下加入tools:replace="android:icon, android:theme"(多个属性用,隔开,而且记住在manifest根标签上加入xmlns:tools="http://schemas.android.com/tools",否则会找不到namespace哦)
Suggestion: add ‘tools:replace="android:theme"‘ to <activity> element at AndroidManifest.xml:1120:9-1128:20 to override.
这个错误就是<activity>合并时冲突了。和application一样,依据冲突提示加入就可以,如:
<activity
tools
:replace="android:configChanges"
android
:name="xxxxx"
android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|fontScale|uiMode|screenSize|smallestScreenSize"
android
:label="@string/N64_Name"
android
:process=":game"
android
:theme="@style/appTheme.Black">
</activity>
10.
AAPT err(Facade for 1813194376): libpng error: Not a PNG file
Error:Execution failed for task ‘:xxxx:mergeDebugResources‘.
> Some file crunching failed, see logs for details
原因是jpg格式的图片后缀为png,AS校验严格,eclipse不校验
使用美图工具将图片转为png图片
11.
Error:Execution failed for task ‘:xxx:processDebugManifest‘.
> F:\xxx\src\main\AndroidManifest.xml:329:9-335:20: Error: Invalid instruction ‘targetApi‘, valid instructions are : REMOVE,REPLACE,STRICT
解决:
<activity
android
:name="xxxx"
android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|fontScale|uiMode|screenSize|smallestScreenSize"
android
:label="@string/app_name"
android
:theme="@android:style/Theme.Holo.Light.Dialog"
tools
:targetApi="11">
</activity>
把Manifest中tools:targetApi="11"去掉
12.
把定义的接口类单独提出来,不要写在类里面,不然会以为循环继承
13.
Error:Execution failed for task ‘:xxxx:transformResourcesWithMergeJavaResForDebug‘.
> com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK META-INF/maven/com.squareup.okio/okio/pom.xml
File1: xxx\libs\com.umeng.message.lib_v2.3.0.jar
File2: xxx\build\intermediates\exploded-aar\xxx\unspecified\jars\classes.jar
友盟的sdk和其它jar冲突
解决:
1)添加配置(好像没用)
packagingOptions {
exclude
‘META-INF/NOTICE‘
// will not include NOTICE file
exclude
‘META-INF/LICENSE‘
// will not include LICENSE file
}
2)更新友盟新的sdk
Error:Execution failed for task ‘:xxx:transformResourcesWithMergeJavaResForDebug‘.
> com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK META-INF/maven/com.squareup.okio/okio/pom.xml
File1: C:\Users\Administrator\.gradle\caches\modules-2\files-2.1\com.squareup.okio\okio\1.2.0\c0b52915a48fa91b1b94a28d4a2997bac5f524df\okio-1.2.0.jar
File2: xxx\build\intermediates\exploded-aar\branch_20151216_1.5.0_01_copy\emuUtils\unspecified\jars\classes.jar
解决:配置
packagingOptions {
exclude‘META-INF/maven/com.squareup.okio/okio/pom.xml‘
exclude‘META-INF/maven/com.squareup.okio/okio/pom.properties‘
}
友盟推送sdk使用了okio包,我的项目libray中也调用了。合并时冲突。
我友盟pushsdk中的okio包去掉。引用libray就可以。
14.
Error:Execution failed for task ‘:xxx:transformClassesWithDexForDebug‘.
> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process ‘command
‘C:\Program Files\Java\jdk1.8.0_73\bin\java.exe‘‘ finished with non-zero exit value 2
解决:
主project和libray引用的包反复了,这个问题比較麻烦,因为项目中有10多个libray,要细致排插反复的jar。
15.
最终成功后,桌面出现多个图标
解决:把每一个libray的配置MAIN删掉
<intent-filter>
<action
android
:name="android.intent.action.MAIN"/>
<category
android
:name="android.intent.category.LAUNCHER"/>
</intent-filter>
16.
打包时出现的错误
Error:(2) Error: In Gradle projects, always use http://schemas.android.com/apk/res-auto for custom attributes [ResAuto]
解决:
<ScrollViewxmlns:app="http://schemas.android.com/apk/res/xx.xxx.xxx"
xmlns:android="http://schemas.android.com/apk/res/android"
改为:
<ScrollViewxmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"