Unity打包APK失败,提示UnityPlayerActivity.java使用或覆盖了已过时的 API。

Unity打包APK失败,提示:Temp\gradleOut\unityLibrary\src\main\java\com\unity3d\player\UnityPlayerActivity.java使用或覆盖了已过时的 API。

仔细看下输出,其实原因已经很明显了,billing-3.0.3.aar和com.android.billingclient-billing-3.0.3.arr里都包含了classes.jar,删掉一个billing包就可以了。

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

最近升级billing-3.0.3到billing-5.0.0,然后打包的时候又遇到了新的问题,如下:

 

CommandInvokationFailure: Gradle build failed. 
D:/Program Files/Unity Hub/2019.4.30f1c3/Editor/Data/PlaybackEngines/AndroidPlayer\OpenJDK\bin\java.exe -classpath "D:\Program Files\Unity Hub\2019.4.30f1c3\Editor\Data\PlaybackEngines\AndroidPlayer\Tools\gradle\lib\gradle-launcher-5.1.1.jar" org.gradle.launcher.GradleMain "-Dorg.gradle.jvmargs=-Xmx4096m" "assembleRelease"

stderr[
H:\XX_Android\Temp\gradleOut\launcher\src\main\AndroidManifest.xml:15:13-34 Error:
	Attribute meta-data#com.google.android.play.billingclient.version@value value=(3.0.3) from [:billing-3.0.3:] AndroidManifest.xml:15:13-34
	is also present at [:com.android.billingclient-billing-5.0.0:] AndroidManifest.xml:15:13-34 value=(5.0.0).
	Suggestion: add 'tools:replace="android:value"' to <meta-data> element at AndroidManifest.xml:13:9-15:37 to override.

FAILURE: Build failed with an exception.

然后按这个提示,在Plugins/Android目录下的AndroidManifest.xml中添加了代码:

<meta-data tools:replace="android:value" android:name="com.google.android.play.billingclient.version" android:value="value"/>

重新编译又提示新的异常:

注: H:\XX_Android\Temp\gradleOut\unityLibrary\src\main\java\com\unity3d\player\UnityPlayerActivity.java使用或覆盖了已过时的 API。
注: 有关详细信息, 请使用 -Xlint:deprecation 重新编译。

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':launcher:checkReleaseDuplicateClasses'.
> 1 exception was raised by workers:
  java.lang.RuntimeException: Duplicate class com.android.billingclient.BuildConfig found in modules classes.jar (:billing-3.0.3:) and classes.jar (:com.android.billingclient-billing-5.0.0:)
  Duplicate class com.android.billingclient.api.AccountIdentifiers found in modules classes.jar (:billing-3.0.3:) and classes.jar (:com.android.billingclient-billing-5.0.0:)
  Duplicate class com.android.billingclient.api.AcknowledgePurchaseParams found in modules classes.jar (:billing-3.0.3:) and classes.jar (:com.android.billingclient-billing-5.0.0:)
  Duplicate class com.android.billingclient.api.AcknowledgePurchaseParams$Builder found in modules classes.jar (:billing-3.0.3:) and classes.jar (:com.android.billingclient-billing-5.0.0:)
  Duplicate class com.android.billingclient.api.AcknowledgePurchaseResponseListener found in modules classes.jar (:billing-3.0.3:) and classes.jar (:com.android.billingclient-billing-5.0.0:)

把Plugins/Android目录下的com.android.billingclient-billing-5.0.0.arr删掉,打包是没问题了,但是安装到机器上启动的时候,又提示NoClassDefFoundError,

 有点头大,不过最后在Unity编辑器上找到的原因,在Unity的Window/Package Manager下,发现有安装In App Purchasing(完全没印象什么时候安装了这个)。。把它删掉然后再还原之前5.0.0的包,再重新打包然后安装启动,一切都正常了。

  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值