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

解决:
在manifest里面,某个activity下多写了一句intent-filter,里面没有内容,删了之后就没错误了。


2.

错误例如以下:
解决:

使用NDK时。NDK not configured

http://stackoverflow.com/questions/20674650/how-to-configure-ndk-with-android-gradle-plugin-0-7

在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.

watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="">


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"

eclipse转Android studio遇到的那些坑的更多相关文章

  1. Eclipse和Android Studio中的DDMS使用时什么不同?

    http://www.jb51.net/softjc/454131.html Eclipse和Android Studio中的DDMS使用时什么不同? 相信很多经常开发Android应用的朋友应该都接 ...

  2. 将应用代码由eclipse导入Android studio的方法NDK-Build和Cmake两种方法(以android_serialport_api为例)

    网上翻了几百篇博客,看了半天,要不就是写的乱七八糟看不懂,要不就是隐藏了一些细节,要不就是实现不了,最后还是在Android官网上看明白了,而且说得有条有理,以后遇到不懂的一定要先翻官网. 参考资料: ...

  3. Eclipse转Android Studio工程实践

    Eclipse转Android Studio工程有两种方式, 一种是兼容Eclipse,两者都可以使用,一种是全新的Android Gradle Project. 这里使用的Android Studi ...

  4. Android Studio(七):项目从Eclipse到Android Studio迁移

    Android Studio相关博客: Android Studio(一):介绍.安装.配置 Android Studio(二):快捷键设置.插件安装 Android Studio(三):设置Andr ...

  5. 移动开发必须要弄明白的问题】详解Eclipse转Android Studio

    2015-12-09 13:01:244264浏览3评论 AS出来一年多了,最近才从Eclipse转到AS,但我并不觉得使用Eclipse有多落后,它们都只是一个工具而已,哪个顺手就用哪个,用得好都能 ...

  6. 常用快捷键: From Eclipse to Android Studio

    Eclipse: ctrl+shift+L查看所有快捷键 alt+shift+r 重命名 ctrl+shift+F 格式化代码 alt+shift+s  添加未实现方法 alt+/ 代码助手提示 ct ...

  7. NDK开发-简介&环境搭建(Eclipse,Android Studio)

    NDK简介 NDK(Native Development Kit)是一套工具集,允许你在Android应用中嵌入c或c++. 使用NDK的好处主要有以下4点: 安全:由于apk的java层代码很容易被 ...

  8. Ubuntu中给eclipse和android studio添加桌面快捷图标

    Ubuntu 12.04 创建应用程序启动项(可在Unity LaucherPad显示) http://www.cnblogs.com/bluestorm/archive/2012/10/12/272 ...

  9. eclipse 和 android studio 打包签名apk问题

    首先,我使用eclipse打包了一个签名apk 然后,我使用同一个签名文件在android studio 打包同一个项目 接下来,首先安装eclipse 打包的apk,然后安装android stud ...

随机推荐

  1. Swift - 将String类型的数字转换成数字类型(支持十进制、十六进制)

    1,十进制的字符串转成数字 Swift中,如果要把字符串转换成数字类型(比如整型,浮点型等).可以先转成NSString类型,让后再转. 1 2 3 4 //将文本框中的值转换成数字 var i = ...

  2. Vue常用插件总结

    Vue-router ----- 路由插件 Vue-loader-----webpack的加载器,允许您以称为单文件组件(SFC)的格式创作Vue组件   Vue-resource-----提供了使用 ...

  3. MySQL架构与SQL执行流程

    MySQL架构设计 下面是一张MySQL的架构图: 上方各个组件的含义如下: Connectors 指的是不同语言中与SQL的交互 Management Serveices & Utiliti ...

  4. win7如何给虚拟机设置共享文件

    友情提示:设置之前先把虚拟机关掉 1. 安装vmtools 安装过的,则不需要 重新安装 如果没有安装vmware tools,点击安装(需要联网下载) ,下载完成后,打开虚拟机 点击安装,安装完毕后 ...

  5. window下安装git

  6. 使用Micrisoft.net设计方案 第二章组织模式

    第二章组织模式 模式不仅依赖于它所包含的更小模式,同时也依赖包含它的更大的模式.它是描述复杂软件的系统方法. 本章的目标是让我们了解以下问题: 1.如何标识模式与模式的关系 2.如何把模式组织成模式集 ...

  7. android黑科技系列——微信抢红包插件原理解析和开发实现

    一.前言 自从几年前微信添加抢红包的功能,微信的电商之旅算是正式开始正式火爆起来.但是作为Android开发者来说,我们在抢红包的同时意识到了很多问题,就是手动去抢红包的速度慢了,当然这些有很多原因导 ...

  8. Paint、Canvas.2

    1:使用Cavans画个简单图形 2:过程 2.1:绘制最外部的圆 /*** 初始化 paint */ Paint paint; paint = new Paint(); paint.setColor ...

  9. 利用Axis2默认口令安全漏洞入侵WebService网站

    近期,在黑吧安全网上关注了几则利用Axis2默认口令进行渗透测试的案例,大家的渗透思路基本一致,利用的技术工具也大致相同,我在总结这几则案例的基础之上进行了技术思路的拓展.黑吧安全网Axis2默认口令 ...

  10. 路飞学城Python-Day79

    27-url控制器之path方法 由于基于re_path的路径编写方式是重复性高的编写url,如果规则改变了,则对应的要去修改很多url,这样是很不方便的 所以采用Django2.0的path去编写u ...