博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
eclipse转Android studio遇到的那些坑
阅读量:6948 次
发布时间:2019-06-27

本文共 6326 字,大约阅读时间需要 21 分钟。

       公司项目有导入10多个libray,还有涉及ndk,转Android studio时碰到不少问题。前后大概花费5个工作日,中间各种奇葩bug,各种编译出错,非常多还有没错误提示。一度想过放弃,如不是没有选择,可能真要放弃了。最后成功转型还是非常值得的。现记录下遇到的问题,给有须要的人。
1.
解决:
在manifest里面,某个activity下多写了一句intent-filter,里面没有内容,删了之后就没错误了。

2.
错误例如以下:
解决:

使用NDK时。NDK not configured

在NDK libproject下的 build.gradle中加入
1
2
3
4
5
6
7
8
9
10
11
12
productFlavors {
       
arm {
           
ndk {
           
abiFilters
"armeabi"
,
"armeabi-v7a"
           
}
       
}
       
x86 {
           
ndk {
           
abiFilter
"x86"
           
}
       
}
       
}

或者

1
2
3
4
5
6
7
buildTypes {
     
debug {
     
ndk {
         
abiFilters
"armeabi"
,
"armeabi-v7a"
     
}
     
}
 }
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]
解决:
<ScrollView
xmlns:
app
=
"http://schemas.android.com/apk/res/xx.xxx.xxx"
   xmlns:
android
=
"http://schemas.android.com/apk/res/android"
改为:
<ScrollView
xmlns:
app
=
"http://schemas.android.com/apk/res-auto"
   xmlns:
android
=
"http://schemas.android.com/apk/res/android"

转载于:https://www.cnblogs.com/gavanwanggw/p/7093105.html

你可能感兴趣的文章
Backup: Array in Perl6
查看>>
ansible常用模块
查看>>
【C++】typeinfo.h
查看>>
Asp.net使用powershell管理hyper-v
查看>>
ASP.NET(C#)图片加文字、图片水印(转)
查看>>
python 爬虫
查看>>
连接ssh反应很慢,卡,延迟
查看>>
rabbitmq基本操作
查看>>
疑问????
查看>>
Leetcode 515. Find Largest Value in Each Tree Row
查看>>
WINCE 下载地址(转)
查看>>
日期操作积累
查看>>
Linux 僵尸进程的筛选和查杀
查看>>
WP7基础学习---第十五讲
查看>>
mysql linux app
查看>>
DotNetCore学习-3.管道中间件
查看>>
Python基础11_函数名运用,闭包,迭代器
查看>>
java集合框架
查看>>
python之configparse模块
查看>>
用户数据文件损坏
查看>>