ADMOB的打包问题

今天在添加了admob广告包进行打包时,出现了个Exception

UNEXPECTED TOP-LEVEL EXCEPTION:

java.lang.lllegalArgumentException:already added La,查了好久,重要找到了篇靠谱的外文,解决了问题。

简单点说呢,就是admob包在打包的时候进行了混淆,但是没有去自定义package name,在你又添加了另外一个jar包,类里面有冲突的名称。我觉得和引用库工程和主干版本的资源重复差不多吧(这里会有一个默认优先级比较高,不会报错)。解决办法如下:在混淆的代码中添加上

-repackageclasses 'custom.package.here'

一个简单的打混淆的target

    <!--Execute proguard class flies-->
    <target name="optimize">
        <jar basedir="${outdir-classes}" destfile="temp.jar"/>
        <java jar="${proguard-home}/proguard.jar" fork="true" failοnerrοr="true">
            <jvmarg value="-Dmaximum.inlined.code.length=32"/>
            <arg value="-injars temp.jar"/>
            <arg value="-outjars optimized.jar"/>
            <arg value="-libraryjars ${android-jar}"/>
       
            <!--  <arg value="-libraryjars ${external-libs}/*.jar"/>-->
            <arg value="-dontpreverify"/>
            <arg value="-dontoptimize"/>
            <arg value="-dontusemixedcaseclassnames"/>
            <arg value="-repackageclasses 'packagename' "/>
            <arg value="-allowaccessmodification"/>
            <!--<arg value="-keep public class ${exclude-activity}"/>-->
            <!--<arg value="-keep public class ${exclude-provider}"/>-->
            <arg value="-keep public class * extends android.app.Activity"/>
            <arg value="-keep public class * extends android.content.ContentProvider"/>
            <arg value="-keep public class * extends android.view.View"/>
            <arg value="-keep public class * extends android.preference.Preference"/>             <arg value="-optimizationpasses 7"/>
            <arg value="-verbose"/>
            <arg value="-dontskipnonpubliclibraryclasses"/>
            <arg value="-dontskipnonpubliclibraryclassmembers"/>
        </java>
        <delete file="temp.jar"/>
        <delete dir="${outdir-classes}"/>
        <mkdir dir="${outdir-classes}"/>
        <unzip src="optimized.jar" dest="${outdir-classes}"/>
        <delete file="optimized.jar"/>
    </target>


下面是引用的外文:

One of our team members (thanks Shalin!) recently discovered that our Android library didn't play well with AdMob. As soon as our library and AdMob's library were added to the same project, this error showed up:

---------------------------------------------------------------------------------

UNEXPECTED TOP-LEVEL EXCEPTION:

java.lang.IllegalArgumentException: already added: ...

....

Conversion to Dalvik format failed with error 1

---------------------------------------------------------------------------------

Here is a stack overflow post that describes other users experiencing similar issues with other jar files. There are many suggested solutions, but none of them worked. After I poked around the AdMob Android library, the real issue became clear -- AdMob's library uses ProGuard to obfuscate its classes, but fails to declare a custom package name. Proguard will change your classes and its imports to look something like:

import A;
import B;
import C
etc

This means if you add other external libraries that are also guilty of this (like ours!), the classes will have conflicting names and you won't be build your project. We have since fixed our Android library with one line of (configuration) code, and we invite Google to do the same.

If you are developing a library, and use ProGuard to obfuscate your classes, then

Add this line to your proguard.cfg file:

-repackageclasses 'custom.package.here'

This will change your classes to custom.package.here.A, custom.package.here.B, etc. Now they'll no longer conflict!

参考:http://blog.crittercism.com/admob-unfriendly-jar-on-android

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
如果您想将HTML5游戏加入Admob广告,并将其打包成iOS应用程序(.ipa文件),您需要遵循以下步骤: 1. 将HTML5游戏包装成iOS应用程序 您可以使用工具如PhoneGap、Cordova或Ionic等将HTML5游戏打包成iOS应用程序(.ipa文件)。这些工具提供了简单易用的界面,可以帮助您快速打包应用程序,而无需太多的编程经验。 2. 集成Admob SDK 在将HTML5游戏打包成iOS应用程序之前,您需要将Admob SDK集成到应用程序中。您可以在Admob的开发者文档中找到适合您的平台和语言的SDK,并按照文档中的步骤进行集成。在集成SDK时,您需要提供应用程序的Bundle ID,并在Admob中创建相应的应用。 3. 创建广告单元 在Admob中创建广告单元,以便在应用程序中显示广告。您可以选择不同的广告类型和尺寸,并将其与您的应用关联。 4. 在应用程序中显示广告 在您的iOS应用程序中,您可以使用Admob提供的API调用广告单元,并将广告显示在游戏中。您可以选择在应用程序中的适当位置显示广告,以获得最佳的展示效果。 5. 打包应用程序 当您完成应用程序的开发和广告集成后,您可以使用Xcode或其他打包工具将应用程序打包成iOS应用程序(.ipa文件)。您需要使用Apple Developer账户来签署和分发应用程序。 需要注意的是,在添加广告时需要遵守Admob的政策和规定,以确保广告收益的合法性和稳定性。同时,您需要遵循Apple的开发者规定和审核要求,以确保您的应用程序能够通过审核并在App Store上发布。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值