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,
文章来源:https://www.toymoban.com/news/detail-505518.html
有点头大,不过最后在Unity编辑器上找到的原因,在Unity的Window/Package Manager下,发现有安装In App Purchasing(完全没印象什么时候安装了这个)。。把它删掉然后再还原之前5.0.0的包,再重新打包然后安装启动,一切都正常了。文章来源地址https://www.toymoban.com/news/detail-505518.html
到了这里,关于Unity打包APK失败,提示UnityPlayerActivity.java使用或覆盖了已过时的 API。的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!