as 上导入将eclipse项目导入成module遇到的一些问题

故事背景:刚接手公司的两个项目(ps:很老的eclispe两个项目,其中一个被我改造成了as项目),需求要求把另外一个eclipse项目导入到as项目里面成为其中的一个module。历时一天半,晚上加班到12点,才搞定,中间大大小小碰到很多问题。这里记录的只有一部分,时间很紧没时间去做记录。
Bug No.1
Caused by: java.lang.RuntimeException: java.util.zip.ZipException: invalid entry size (expected 286448 but got 286477 bytes)
细心点可以发现这个问题下面会有addJar相关的api调用。
我推测可能是有相同重复jar,于是对四五个module进行了jar的去重。
因为中间进行了大量的操作, 所以不确定是否是这个操作修改好的。
Bug No.2(出现次数非常多)
Error:Error:Executionfailed for task ‘:greencar:processDebugManifest’.> Manifest merger failed withmultipleerrors, see logs。
根据错误提示可以看出是清单文件合并相同的属性造成的错误,具体的合并规则可以看一下官方的链接(后面补上)
解决方案:
在manifest根标签上加入xmlns:tools=”http://schemas.android.com/tools“,并在Manifest.xml的application标签下添加tools:replace=”name,icon, label,heme”
Bug No.3
error:在作为library的项目中的R文件报错:需要常量表达式
解决方案:
在一般的Android项目中,R类的常量都是用final定义的,但ADT 14之后,如果在library 项目中,它会没有final关键字,而我们在作为library的项目中使用了switch ,在switch语句的case中,如果使用 R.id.xxx 则会提示有问题,不允许非常量在case语句中。
Google提供的一个方法就是把它转化为if-else语句
Bug No.4
java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file “/data/app/com.haocang.maxprd-2/base.apk”],nativeLibraryDirectories=[/data/app/com.haocang.maxprd-2/lib/arm64, /system/fake-libs64, /data/app/com.haocang.maxprd-2/base.apk!/lib/arm64-v8a, /system/lib64, /vendor/lib64]]] couldn’t find “libutility.so”

根据错误提示可以看到couldn’t find “libutility.so”找不到。
解决办法删除了一个so文件夹

《as 上导入将eclipse项目导入成module遇到的一些问题》 图片来源于网络

关于so文件夹的作用可以看看这个链接
http://blog.csdn.net/mao520741111/article/details/50328669

Bug No.5
Attribute “xxx” has already been defined
原因是在定义属性时,两个属性集里定义了两个相同的属性。

<? xml version = "1.0" encoding = "utf-8" ?>  
< resources >  
     < declare-styleable name= "PreferenceHeader" >  
        <!-- Identifier value for the header. -->  
        < attr name= "id" format = "integer"/>  
        < attr name= "icon" format = "integer" />  
        <!-- The fragment that is displayed when the user selects this item. -->  
    </declare-styleable >  
    < declare-styleable name= "Preference" >  
        < attr name= "icon" format = "integer" />  
        <!-- The key to store the Preference value. -->  
        < attr name= "key" format = "string" />  
    </declare-styleable >  
</ resources >  

icon属性被重复定义
解决办法
在属性集外面申明一下被重复的属性
< attr name = “icon” format = “integer” />

Bug No.6
com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: com/xxxx/xxxx/device/xxxxx.class
出现这个问题跟前面差不多,在执行代码class合并时出现类或者jar重复,我的原因是两个项目都含有相同类,且包名也是一模一样。
解决办法: 把其中一个包的包名更改了, 当然你也可以抽取一个单独的base module。

Bug No.7
项目安装到手机同时出现了四个图标,原因是library里面的清单文件含有下面的代码

            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>

这个细想其实很好理解,提示LAUNCHER

    原文作者:D焱炎
    原文地址: https://www.jianshu.com/p/c1fb65d39acc
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞