欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Unity上线google商店 用IL2Cpp打包64位版本和Android APP Bundle优化 及产生的bug

程序员文章站 2022-03-19 23:38:27
ios刚上线,这边着手改成android版本,我开始使用的是unity2017.4.1版本 上传谷歌商店是出现这两个警告: 要支持64位,但是在2017版本上没有找到64位的打包选项,猜测应该是版本的问题,上网查询果然是 以下是我查询的: https://www.cnblogs.com/cnxkey ......

ios刚上线,这边着手改成android版本,我开始使用的是unity2017.4.1版本

上传谷歌商店是出现这两个警告:

Unity上线google商店  用IL2Cpp打包64位版本和Android APP Bundle优化 及产生的bug

 

要支持64位,但是在2017版本上没有找到64位的打包选项,猜测应该是版本的问题,上网查询果然是

以下是我查询的:

https://www.cnblogs.com/cnxkey/articles/9760391.html

http://tieba.baidu.com/p/5496282855

http://dy.163.com/v2/article/detail/e9lqnd6m0526e124.html

怎样打包64位和androi app bundle上面他们讲解的都很详细,而且还讲解了为什么google要支持64位,非常感谢他们分享。

一:我下载了新的unity2018.4.1,开始先键一个demo,里面就随便建了个ui,然后开始打包

1:在playsettings->other settings->scriptiing backend 选择il2cpp(默认是mono),

c++ compiler configuration 选择release

target architectures 里面的arm64就是可以说勾选的了,勾选打包即可

2:androi app bundley优化在build sttings 勾选build app bundle(google play)即可,打出的是aab包

 打包运行成功。

注:要死测试的话就用mono打包吧,毕竟il2cpp打包要慢上几倍

二:2017.4.1转成2018.4.1时产生的部分bug

1:google admob 产生广告bug

在2017.4.1广告是没问题的,移植到2018版本出现此问题

e/unity: androidjavaexception: java.lang.classnotfoundexception: com.google.android.gms.ads.adrequest$builder
java.lang.classnotfoundexception: com.google.android.gms.ads.adrequest$builder
at java.lang.class.classforname(native method)
at java.lang.class.forname(class.java:308)
at java.lang.class.forname(class.java:272)
at com.unity3d.player.unityplayer.nativerender(native method)
at com.unity3d.player.unityplayer.c(unknown source)
at com.unity3d.player.unityplayer$e$2.queueidle(unknown source)
at android.os.messagequeue.next(messagequeue.java:211)
at android.os.looper.loop(looper.java:122)
at com.unity3d.player.unityplayer$e.run(unknown source)
caused by: java.lang.classnotfoundexception: didn't find class "com.google.android.gms.ads.adrequest$builder" on path: dexpathlist[[zip file "/data/app/com.newqwx.crushminer-1/base.apk"],nativelibrarydirectories=[/data/app/com.newqwx.crushminer-1/lib/arm, /vendor/lib, /system/lib]]
at dalvik.system.basedexclassloader.findclass(basedexclassloader.java:56)
at java.la

beginning of crash

 e/androidruntime: fatal exception: main
process: com.newqwx.crushminer, pid: 13331
java.lang.error: fatal exception [main]
unity version : 2018.4.1f1
device model : motorola nexus 6
device fingerprint: google/shamu/shamu:5.0/lrx21o/1570415:user/release-keys

caused by: java.lang.noclassdeffounderror: failed resolution of: lcom/google/android/gms/ads/mobileads;
at com.google.unity.ads.rewardbasedvideo$1.run(rewardbasedvideo.java:65)
at android.os.handler.handlecallback(handler.java:739)
at android.os.handler.dispatchmessage(handler.java:95)
at android.os.looper.loop(looper.java:135)
at android.app.activitythread.main(activitythread.java:5221)
at java.lang.reflect.method.invoke(native method)
at java.lang.reflect.method.invoke(method.java:372)
at com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:899)
at com.android.internal.os.zygoteinit.main(zygoteinit.java:694)
caused by: java.lang.classnotfoundexception: didn't find class "com.google.android.gms.ads.mobileads" on path: dexpathlist[[zip file "/data/app/com.newqwx.crushminer-1/base.apk"],nativelibrarydirectories=[/data/app/com.newqwx.crushminer-1/lib/arm, /vendor/lib, /system/lib]]
at dalvik.system.basedexclassloader.findclass(basedexclassloader.java:56)
at java.lang.classloader.loadclass(classloader.java:511)
at java.lang.classloader.loadclass(classloader.java:469)
at com.google.unity.ads.rewardbasedvideo$1.run(rewardbasedvideo.java:65)?
at android.os.handler.handlecallback(handler.java:739)?
at android.os.handler.dispatchmessage(handler.java:95)?
at android.os.looper.loop(looper.java:135)?
at android.app.activitythread.main(activitythread.java:5221)?
at java.lang.reflect.method.invoke(native method)?
at java.lang.reflect.method.invoke(method.java:372)?
at com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:899)?
at com.android.internal.os.zygoteinit.main(zygoteinit.java:694)?
suppressed: java.lang.classnotfoundexception: com.google.android.gms.ads.mobileads
at java.lang.class.classforname(native method)
at java.lang.bootclassloader.findclass(classloader.java:781)
at java.lang.bootclassloader.loadclass(classloader.java:841)
at java.lang.classloader.loadclass(classloader.java:504)
... 10 more
caused by: java.lang.noclassdeffounderror: class not found using the boot class loader; no stack available

解决方法:assets->play services resolver ->android resolver->resolve 解决

但由此可能产生下面打包的bug

2:产生的打包的gradle错误

commandinvokationfailure: gradle build failed.
d:/java/jdk1.8.0_181\bin\java.exe -classpath "d:\unity2018.4\editor\data\playbackengines\androidplayer\tools\gradle\lib\gradle-launcher-4.6.jar" org.gradle.launcher.gradlemain "-dorg.gradle.jvmargs=-xmx4086m" "assemblerelease"

stderr[
d8: program type already present: android.support.v4.accessibilityservice.accessibilityserviceinfocompat

failure: build failed with an exception.

* what went wrong:
execution failed for task ':transformdexarchivewithexternallibsdexmergerforrelease'.
> com.android.builder.dexing.dexarchivemergerexception: error while merging dex archives: f:\unity\crushminer\crushminer9.11optimize2018.4.1\temp\gradleout\build\intermediates\transforms\dexbuilder\release\27.jar, f:\unity\crushminer\crushminer9.11optimize2018.4.1\temp\gradleout\build\intermediates\transforms\dexbuilder\release\35.jar, f:\unity\crushminer\crushminer9.11optimize2018.4.1\temp\gradleout\build\intermediates\transforms\dexbuilder\release\73.jar, f:\unity\crushminer\crushminer9.11optimize2018.4.1\temp\gradleout\build\intermediates\transforms\dexbuilder\release\31.jar, f:\unity\crushminer\crushminer9.11optimize2018.4.1\temp\gradleout\build\intermediates\transforms\dexbuilder\release\74.jar, f:\unity\crushminer\crushminer9.11optimize2018.4.1\temp\gradleout\build\intermediates\transforms\dexbuilder\release\57.jar, f:\unity\crushminer\crushminer9.11optimize2018.4.1\temp\gradleout\build\intermediates\transforms\dexbuilder\release\29.jar, f:\unity\crushminer\crushminer9.11optimize2018.4.1\temp\gradleout\build\intermediates\transforms\dexbuilder\release\34.jar, f:\unity\crushminer\crushminer9.11optimize2018.4.1\temp\gradleout\build\intermediates\transforms\dexbuilder\release\58.jar, f:\unity\crushminer\crushminer9.11optimize2018.4.1\temp\gradleout\build\intermediates\transforms\dexbuilder\release\36.jar, f:\unity\crushminer\crushminer9.11optimize2018.4.1\temp\gradleout\build\intermediates\transforms\dexbuilder\release\26.jar, f:\unity\crushminer\crushminer9.11optimize2018.4.1\temp\gradleout\build\intermediates\transforms\dexbuilder\release\32.jar, f:\unity\crushminer\crushminer9.11optimize2018.4.1\temp\gradleout\build\intermediates\transforms\dexbuilder\release\37.jar, f:\unity\crushminer\crushminer9.11optimize2018.4.1\temp\gradleout\build\intermediates\transforms\dexbuilder\release\30.jar, f:\unity\crushminer\crushminer9.11optimize2018.4.1\temp\gradleout\build\intermediates\transforms\dexbuilder\release\65.jar, f:\unity\crushminer\crushminer9.11optimize2018.4.1\temp\gradleout\build\intermediates\transforms\dexbuilder\release\22.jar, f:\unity\crushminer\crushminer9.11optimize2018.4.1\temp\gradleout\build\intermediates\transforms\dexbuilder\release\48.jar, f:\unity\crushminer\crushminer9.11optimize2018.4.1\temp\gradleout\build\intermediates\transforms\dexbuilder\release\0.jar, f:\unity\crushminer\crushminer9.11optimize2018.4.1\temp\gradleout\build\intermediates\transforms\dexbuilder\release\14.jar, f:\unity\crushminer\crushminer9.11optimize2018.4.1\temp\gradleout\build\intermediates\transforms\dexbuilder\release\1.jar, f:\unity\crushminer\crushminer9.11optimize2018.4.1\temp\gradleout\build\intermediates\transforms\dexbuilder\release\23.jar, f:\unity\crushminer\crushminer9.11optimize2018.4.1\temp\gradleout\build\intermediates\transforms\dexbuilder\release\9.jar, f:\unity\crushminer\crushminer9.11optimize2018.4.1\temp\gradleout\build\intermediates\transforms\dexbuilder\release\49.jar, f:\unity\crushminer\crushminer9.11optimize2018.4.1\temp\gradleout\build\intermediates\transforms\dexbuilder\release\41.jar, f:\unity\crushminer\crushminer9.11optimize2018.4.1\temp\gradleout\build\intermediates\transforms\dexbuilder\release\15.jar, f:\unity\crushminer\crushminer9.11optimize2018.4.1\temp\gradleout\build\intermediates\transforms\dexbuilder\release\59.jar, f:\unity\crushminer\crushminer9.11optimize2018.4.1\temp\gradleout\build\intermediates\transforms\dexbuilder\release\7.jar, f:\unity\crushminer\crushminer9.11optimize2018.4.1\temp\gradleout\build\intermediates\transforms\dexbuilder\release\46.jar, f:\unity\crushminer\crushminer9.11optimize2018.4.1\temp\gradleout\build\intermediates\transforms\dexbuilder\release\33.jar, f:\unity\crushminer\crushminer9.11optimize2018.4.1\temp\gradleout\build\intermediates\transforms\dexbuilder\release\63.jar, f:\unity\crushminer\crushminer9.11optimize2018.4.1\temp\gradleout\build\intermediates\transforms\dexbuilder\release\16.jar, f:\unity\crushminer\crushminer9.11optimize2018.4.1\temp\gradleout\build\intermediates\transforms\dexbuilder\release\40.jar, f:\unity\crushminer\crushminer9.11optimize2018.4.1\temp\gradleout\build\intermediates\transforms\dexbuilder\release\6.jar, f:\unity\crushminer\crushminer9.11optimize2018.4.1\temp\gradleout\build\intermediates\transforms\dexbuilder\release\8.jar, f:\unity\crushminer\crushminer9.11optimize2018.4.1\temp\gradleout\build\intermediates\transforms\dexbuilder\release\47.jar, f:\unity\crushminer\crushminer9.11optimize2018.4.1\temp\gradleout\build\intermediates\transforms\dexbuilder\release\64.jar, f:\unity\crushminer\crushminer9.11optimize2018.4.1\temp\gradleout\build\intermediates\transforms\dexbuilder\release\21.jar, f:\unity\crushminer\crushminer9.11optimize2018.4.1\temp\gradleout\build\intermediates\transforms\dexbuilder\release\17.jar, f:\unity\crushminer\crushminer9.11optimize2018.4.1\temp\gradleout\build\intermediates\transforms\dexbuilder\release\52.jar, f:\unity\crushminer\crushminer9.11optimize2018.4.1\temp\gradleout\build\intermediates\transforms\dexbuilder\release\60.jar, f:\unity\crushminer\crushminer9.11optimize2018.4.1\temp\gradleout\build\intermediates\transforms\dexbuilder\release\51.jar, f:\unity\crushminer\crushminer9.11optimize2018.4.1\temp\gradleout\build\intermediates\transforms\dexbuilder\release\44.jar, f:\unity\crushminer\crushminer9.11optimize2018.4.1\temp\gradleout\build\intermediates\transforms\dexbuilder\release\18.jar, f:\unity\crushminer\crushminer9.11optimize2018.4.1\temp\gradleout\build\intermediates\transforms\dexbuilder\release\4.jar, f:\unity\crushminer\crushminer9.11optimize2018.4.1\temp\gradleout\build\intermediates\transforms\dexbuilder\release\45.jar, f:\unity\crushminer\crushminer9.11optimize2018.4.1\temp\gradleout\build\intermediates\transforms\dexbuilder\release\28.jar, f:\unity\crushminer\crushminer9.11optimize2018.4.1\temp\gradleout\build\intermediates\transforms\dexbuilder\release\53.jar, f:\unity\crushminer\crushminer9.11optimize2018.4.1\temp\gradleout\build\intermediates\transforms\dexbuilder\release\10.jar, f:\unity\crushminer\crushminer9.11optimize2018.4.1\temp\gradleout\build\intermediates\transforms\dexbuilder\release\19.jar, f:\unity\crushminer\crushminer9.11optimize2018.4.1\temp\gradleout\build\intermediates\transforms\dexbuilder\release\50.jar, f:\unity\crushminer\crushminer9.11optimize2018.4.1\temp\gradleout\build\intermediates\transforms\dexbuilder\release\5.jar, f:\unity\crushminer\crushminer9.11optimize2018.4.1\temp\gradleout\build\intermediates\transforms\dexbuilder\release\54.jar, f:\unity\crushminer\crushminer9.11optimize2018.4.1\temp\gradleout\build\intermediates\transforms\dexbuilder\release\11.jar, f:\unity\crushminer\crushminer9.11optimize2018.4.1\temp\gradleout\build\intermediates\transforms\dexbuilder\release\2.jar, f:\unity\crushminer\crushminer9.11optimize2018.4.1\temp\gradleout\build\intermediates\transforms\dexbuilder\release\24.jar, f:\unity\crushminer\crushminer9.11optimize2018.4.1\temp\gradleout\build\intermediates\transforms\dexbuilder\release\38.jar, f:\unity\crushminer\crushminer9.11optimize2018.4.1\temp\gradleout\build\intermediates\transforms\dexbuilder\release\12.jar, f:\unity\crushminer\crushminer9.11optimize2018.4.1\temp\gradleout\build\intermediates\transforms\dexbuilder\release\25.jar, f:\unity\crushminer\crushminer9.11optimize2018.4.1\temp\gradleout\build\intermediates\transforms\dexbuilder\release\62.jar, f:\unity\crushminer\crushminer9.11optimize2018.4.1\temp\gradleout\build\intermediates\transforms\dexbuilder\release\55.jar, f:\unity\crushminer\crushminer9.11optimize2018.4.1\temp\gradleout\build\intermediates\transforms\dexbuilder\release\42.jar, f:\unity\crushminer\crushminer9.11optimize2018.4.1\temp\gradleout\build\intermediates\transforms\dexbuilder\release\39.jar, f:\unity\crushminer\crushminer9.11optimize2018.4.1\temp\gradleout\build\intermediates\transforms\dexbuilder\release\61.jar, f:\unity\crushminer\crushminer9.11optimize2018.4.1\temp\gradleout\build\intermediates\transforms\dexbuilder\release\43.jar, f:\unity\crushminer\crushminer9.11optimize2018.4.1\temp\gradleout\build\intermediates\transforms\dexbuilder\release\13.jar, f:\unity\crushminer\crushminer9.11optimize2018.4.1\temp\gradleout\build\intermediates\transforms\dexbuilder\release\56.jar, f:\unity\crushminer\crushminer9.11optimize2018.4.1\temp\gradleout\build\intermediates\transforms\dexbuilder\release\3.jar
learn how to resolve the issue at https://developer.android.com/studio/build/dependencies#duplicate_classes.
program type already present: android.support.v4.accessibilityservice.accessibilityserviceinfocompat

* try:
run with --stacktrace option to get the stack trace. run with --info or --debug option to get more log output. run with --scan to get full insights.

* get more help at https://help.gradle.org

build failed in 1m 7s
]
stdout[
observed package id 'tools' in inconsistent location 'f:\environment\sdk\android_sdk_tools\android-sdk-windows\temptoolsdir' (expected 'f:\environment\sdk\android_sdk_tools\android-sdk-windows\tools')
:checkreleaseclasspath
:prebuild up-to-date
:googlemobileadsplugin:prebuild up-to-date
:googlemobileadsplugin:prereleasebuild up-to-date
:googlemobileadsplugin:checkreleasemanifest
:googlemobileadsplugin:processreleasemanifest
:ironsource:prebuild up-to-date
:ironsource:prereleasebuild up-to-date
:ironsource:checkreleasemanifest
:ironsource:processreleasemanifest
:unity-android-resources:prebuild up-to-date
:unity-android-resources:prereleasebuild up-to-date
:unity-android-resources:checkreleasemanifest
:unity-android-resources:processreleasemanifest
:prereleasebuild
:googlemobileadsplugin:compilereleaseaidl no-source
:ironsource:compilereleaseaidl no-source
:unity-android-resources:compilereleaseaidl no-source
:compilereleaseaidl no-source
:googlemobileadsplugin:packagereleaserenderscript no-source
:ironsource:packagereleaserenderscript no-source
:unity-android-resources:packagereleaserenderscript no-source
:compilereleaserenderscript up-to-date
:checkreleasemanifest up-to-date
:generatereleasebuildconfig
:preparelintjar up-to-date
:mainapklistpersistencerelease
:generatereleaseresvalues up-to-date
:generatereleaseresources up-to-date
:googlemobileadsplugin:compilereleaserenderscript
:googlemobileadsplugin:generatereleaseresvalues
:googlemobileadsplugin:generatereleaseresources
:googlemobileadsplugin:packagereleaseresources
:ironsource:compilereleaserenderscript
:ironsource:generatereleaseresvalues
:ironsource:generatereleaseresources
:ironsource:packagereleaseresources
:unity-android-resources:compilereleaserenderscript
:unity-android-resources:generatereleaseresvalues
:unity-android-resources:generatereleaseresources
:unity-android-resources:packagereleaseresources
:mergereleaseresources up-to-date
:createreleasecompatiblescreenmanifests
:processreleasemanifest
:splitsdiscoverytaskrelease up-to-date
:googlemobileadsplugin:generatereleaserfile
:ironsource:generatereleaserfile
:unity-android-resources:generatereleaserfile
:processreleaseresources
:generatereleasesources
:googlemobileadsplugin:generatereleasebuildconfig
:googlemobileadsplugin:preparelintjar up-to-date
:googlemobileadsplugin:generatereleasesources
:googlemobileadsplugin:javaprecompilerelease
:googlemobileadsplugin:compilereleasejavawithjavac
:googlemobileadsplugin:processreleasejavares no-source
:googlemobileadsplugin:transformclassesandresourceswithprepareintermediatejarsforrelease
:ironsource:generatereleasebuildconfig
:ironsource:preparelintjar up-to-date
:ironsource:generatereleasesources
:ironsource:javaprecompilerelease
:ironsource:compilereleasejavawithjavac
:ironsource:processreleasejavares no-source
:ironsource:transformclassesandresourceswithprepareintermediatejarsforrelease
:unity-android-resources:generatereleasebuildconfig
:unity-android-resources:preparelintjar up-to-date
:unity-android-resources:generatereleasesources
:unity-android-resources:javaprecompilerelease
:unity-android-resources:compilereleasejavawithjavac
:unity-android-resources:processreleasejavares no-source
:unity-android-resources:transformclassesandresourceswithprepareintermediatejarsforrelease
:javaprecompilerelease
:compilereleasejavawithjavac
:compilereleasendk no-source
:compilereleasesources
:lintvitalrelease
:mergereleaseshaders up-to-date
:compilereleaseshaders up-to-date
:generatereleaseassets up-to-date
:googlemobileadsplugin:mergereleaseshaders
:googlemobileadsplugin:compilereleaseshaders
:googlemobileadsplugin:generatereleaseassets
:googlemobileadsplugin:packagereleaseassets
:ironsource:mergereleaseshaders
:ironsource:compilereleaseshaders
:ironsource:generatereleaseassets
:ironsource:packagereleaseassets
:unity-android-resources:mergereleaseshaders
:unity-android-resources:compilereleaseshaders
:unity-android-resources:generatereleaseassets
:unity-android-resources:packagereleaseassets
:mergereleaseassets
:transformclasseswithdexbuilderforrelease
c:\users\administrator\.gradle\caches\transforms-1\files-1.1\recyclerview-v7.aar\abd41c74047d7be064a61e8696b02349\jars\classes.jar: d8: type `android.support.v4.animation.animatorcompathelper` was not found, it is required for default or static interface methods desugaring of `void android.support.v7.widget.defaultitemanimator.resetanimation(android.support.v7.widget.recyclerview$viewholder)`
c:\users\administrator\.gradle\caches\transforms-1\files-1.1\recyclerview-v7.aar\abd41c74047d7be064a61e8696b02349\jars\classes.jar: d8: interface `android.support.v4.animation.animatorlistenercompat` not found. it's needed to make sure desugaring of `android.support.v7.widget.helper.itemtouchhelper$recoveranimation` is correct. desugaring will assume that this interface has no default method.
c:\users\administrator\.gradle\caches\transforms-1\files-1.1\recyclerview-v7.aar\abd41c74047d7be064a61e8696b02349\jars\classes.jar: d8: interface `android.support.v4.animation.animatorupdatelistenercompat` not found. it's needed to make sure desugaring of `android.support.v7.widget.helper.itemtouchhelper$recoveranimation$1` is correct. desugaring will assume that this interface has no default method.
:transformdexarchivewithexternallibsdexmergerforrelease failed
63 actionable tasks: 52 executed, 11 up-to-date
]
exit code: 1
unityeditor.android.command.waitforprogramtorun (unityeditor.utils.program p, unityeditor.android.waitingforprocesstoexit waitingforprocesstoexit, system.string errormsg)
unityeditor.android.command.run (system.diagnostics.processstartinfo psi, unityeditor.android.waitingforprocesstoexit waitingforprocesstoexit, system.string errormsg)
unityeditor.android.command.run (system.string command, system.string args, system.string workingdir, unityeditor.android.waitingforprocesstoexit waitingforprocesstoexit, system.string errormsg)
unityeditor.android.androidjavatools.runjava (system.string args, system.string workingdir, system.action`1 progress, system.string error)
unityeditor.android.gradlewrapper.run (unityeditor.android.androidjavatools javatools, system.string workingdir, system.string task, system.action`1 progress)
rethrow as gradleinvokationexception: gradle build failed
unityeditor.android.gradlewrapper.run (unityeditor.android.androidjavatools javatools, system.string workingdir, system.string task, system.action`1 progress)
unityeditor.android.postprocessor.tasks.buildgradleproject.execute (unityeditor.android.postprocessor.postprocessorcontext context)

 

解决方法:出现这种问题是jar包重复。

temp\gradleout\build\intermediates\transforms\dexbuilder\release\3.jar(我的最后一个是3.jar,可能不一样)中可以看到:program type already present: android.support.v4.accessibilityservice.accessibilityserviceinfocompat
说明android.support.v4已经存在,就是说有两个,一个新的一个旧的,找到删掉就可以

我的是 support-v4-compat.jar和刚刚导入的 com.android.support.support-v4-26.1.0重复,我删掉了support-v4-compat.jar,就可以打包了

 

3:il2cpp打包时中断,停止运行

 

failed running d:\unity2018.4\editor\data\il2cpp/build/il2cpp.exe --convert-to-cpp --emit-null-checks --enable-array-bounds-check --dotnetprofile="net20" --compile-cpp --libil2cpp-static --platform="android" --architecture="armv7" --configuration="release" --outputpath="f:\unity\crushminer\crushminer9.11optimize2018.4.1\temp/stagingarea\assets\bin\data\native\armeabi-v7a\libil2cpp.so" --cachedirectory="f:\unity\crushminer\crushminer9.11optimize2018.4.1\assets\..\library\il2cpp_android_armeabi-v7a/il2cpp_cache" --additional-include-directories="d:\unity2018.4\editor\data\playbackengines\androidplayer/tools\bdwgc/include" --additional-include-directories="d:\unity2018.4\editor\data\playbackengines\androidplayer/tools\libil2cpp/include" --tool-chain-path="f:/environment/ndk/android-ndk-r16b-windows-x86_64/android-ndk-r16b" --map-file-parser="d:\unity2018.4\editor\data\tools\mapfileparser\mapfileparser.exe" --directory="f:\unity\crushminer\crushminer9.11optimize2018.4.1\temp\stagingarea\assets\bin\data\managed" --generatedcppdir="f:\unity\crushminer\crushminer9.11optimize2018.4.1\temp\stagingarea\il2cpp\il2cppoutput"

stdout:
building libil2cpp.so with androidtoolchain
output directory: f:\unity\crushminer\crushminer9.11optimize2018.4.1\temp\stagingarea\assets\bin\data\native\armeabi-v7a
cache directory: f:\unity\crushminer\crushminer9.11optimize2018.4.1\library\il2cpp_android_armeabi-v7a\il2cpp_cache
objectfiles: 644 of which compiled: 0
total compilation time: 995 milliseconds.
il2cpp.exe didn't catch exception: unity.il2cpp.building.builderfailedexception: f:\environment\ndk\android-ndk-r16b-windows-x86_64\android-ndk-r16b\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++ @"c:\users\administrator\appdata\local\temp\tmp4146.tmp" -o "f:\unity\crushminer\crushminer9.11optimize2018.4.1\library\il2cpp_android_armeabi-v7a\il2cpp_cache\linkresult_37ebd535b6a775512618c151cbf4ce6a\libil2cpp.so" -shared -wl,-soname,libil2cpp.so -wl,--no-undefined -wl,-z,noexecstack -wl,--gc-sections -wl,--build-id --sysroot "f:\environment\ndk\android-ndk-r16b-windows-x86_64\android-ndk-r16b\platforms\android-16\arch-arm" -gcc-toolchain "f:\environment\ndk\android-ndk-r16b-windows-x86_64\android-ndk-r16b\toolchains\arm-linux-androideabi-4.9\prebuilt\windows-x86_64" -target armv7-none-linux-androideabi -wl,--wrap,sigaction -l "f:\environment\ndk\android-ndk-r16b-windows-x86_64\android-ndk-r16b\sources\cxx-stl\gnu-libstdc++\4.9\libs\armeabi-v7a" -lgnustl_static -llog -rdynamic -fuse-ld=gold.exe

f:\unity\crushminer\crushminer9.11optimize2018.4.1\temp\stagingarea\il2cpp\il2cppoutput/bulk_assembly-csharp_9.cpp:34995: error: undefined reference to '_copytopasteboardwithtext'
f:\unity\crushminer\crushminer9.11optimize2018.4.1\temp\stagingarea\il2cpp\il2cppoutput/bulk_assembly-csharp_9.cpp:35099: error: undefined reference to '_sharewithtext'
clang++.exe: error: linker command failed with exit code 1 (use -v to see invocation)


在 unity.il2cpp.building.cppprogrambuilder.postprocessobjectfiles(hashset`1 objectfiles, cpptoolchaincontext toolchaincontext)
在 unity.il2cpp.building.cppprogrambuilder.build(ibuildstatistics& statistics)
在 il2cpp.program.dorun(string[] args)
在 il2cpp.program.run(string[] args)
在 il2cpp.program.main(string[] args)
stderr:

未经处理的异常: unity.il2cpp.building.builderfailedexception: f:\environment\ndk\android-ndk-r16b-windows-x86_64\android-ndk-r16b\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++ @"c:\users\administrator\appdata\local\temp\tmp4146.tmp" -o "f:\unity\crushminer\crushminer9.11optimize2018.4.1\library\il2cpp_android_armeabi-v7a\il2cpp_cache\linkresult_37ebd535b6a775512618c151cbf4ce6a\libil2cpp.so" -shared -wl,-soname,libil2cpp.so -wl,--no-undefined -wl,-z,noexecstack -wl,--gc-sections -wl,--build-id --sysroot "f:\environment\ndk\android-ndk-r16b-windows-x86_64\android-ndk-r16b\platforms\android-16\arch-arm" -gcc-toolchain "f:\environment\ndk\android-ndk-r16b-windows-x86_64\android-ndk-r16b\toolchains\arm-linux-androideabi-4.9\prebuilt\windows-x86_64" -target armv7-none-linux-androideabi -wl,--wrap,sigaction -l "f:\environment\ndk\android-ndk-r16b-windows-x86_64\android-ndk-r16b\sources\cxx-stl\gnu-libstdc++\4.9\libs\armeabi-v7a" -lgnustl_static -llog -rdynamic -fuse-ld=gold.exe

f:\unity\crushminer\crushminer9.11optimize2018.4.1\temp\stagingarea\il2cpp\il2cppoutput/bulk_assembly-csharp_9.cpp:34995: error: undefined reference to '_copytopasteboardwithtext'
f:\unity\crushminer\crushminer9.11optimize2018.4.1\temp\stagingarea\il2cpp\il2cppoutput/bulk_assembly-csharp_9.cpp:35099: error: undefined reference to '_sharewithtext'
clang++.exe: error: linker command failed with exit code 1 (use -v to see invocation)


在 unity.il2cpp.building.cppprogrambuilder.postprocessobjectfiles(hashset`1 objectfiles, cpptoolchaincontext toolchaincontext)
在 unity.il2cpp.building.cppprogrambuilder.build(ibuildstatistics& statistics)
在 il2cpp.program.dorun(string[] args)
在 il2cpp.program.run(string[] args)
在 il2cpp.program.main(string[] args)

unityengine.debug:logerror(object)
unityeditorinternal.runner:runprogram(program, string, string, string, compileroutputparserbase) (at c:/buildslave/unity/build/editor/mono/buildpipeline/buildutils.cs:128)
unityeditorinternal.runner:runmanagedprogram(string, string, string, compileroutputparserbase, action`1) (at c:/buildslave/unity/build/editor/mono/buildpipeline/buildutils.cs:73)
unityeditorinternal.il2cppbuilder:runil2cppwitharguments(list`1, action`1, string) (at c:/buildslave/unity/build/editor/mono/buildpipeline/il2cpp/il2cpputils.cs:368)
unityeditorinternal.il2cppbuilder:convertplayerdlltocpp(string, string, string, boolean) (at c:/buildslave/unity/build/editor/mono/buildpipeline/il2cpp/il2cpputils.cs:349)
unityeditorinternal.il2cppbuilder:run() (at c:/buildslave/unity/build/editor/mono/buildpipeline/il2cpp/il2cpputils.cs:211)
unityeditorinternal.il2cpputils:runil2cpp(string, string, iil2cppplatformprovider, action`1, runtimeclassregistry) (at c:/buildslave/unity/build/editor/mono/buildpipeline/il2cpp/il2cpputils.cs:35)
unityengine.guiutility:processevent(int32, intptr)

 

解决方法:查看中断信息:

在未经处理的异常:下面一段找到error,error: undefined reference to '_copytopasteboardwithtext'

error:undefined reference to '_sharewithtext',说未定义的引用。
 这个可能是你ios的调用方法(我的是ios的方法),然后在代码中找到用条件编译命令#if改掉就ok了

我的方法

[dllimport("__internal")]
private static extern void _copytopasteboardwithtext(string text);

改成
#if unity_ios
[dllimport("__internal")]
private static extern void _copytopasteboardwithtext(string text);
#endif

 

所有问题解决,完美打包运行!!!

 

有什么问题或错误的地方欢迎讨论指正,谢谢。