Unity FBSDK 接入踩坑记录

关于unity 接入 facebook sdk报错解决记录

问题描述:
打包报错“TempgradleOutunityLibrarysrcmainjavacomunity3dplayerUnityPlayerActivity.java使用或覆盖了已过时的 API.”

1.期间我尝试了将包导出到AndroidStudio中打包,查看bug,导入之后不作任何处理然后打包

FAILURE: Build completed with 3 failures.

1: Task failed with an exception.
-----------
* What went wrong:
A problem was found with the configuration of task ':unityLibrary:checkDebugManifest' (type 'CheckManifest').
  - In plugin 'com.android.build.gradle.api.AndroidBasePlugin' type 'com.android.build.gradle.internal.tasks.CheckManifest' property 'manifest' has @Input annotation used on property of type 'File'.
    
    Reason: A property of type 'File' annotated with @Input cannot determine how to interpret the file.
    
    Possible solutions:
      1. Annotate with @InputFile for regular files.
      2. Annotate with @InputDirectory for directories.
      3. If you want to track the path, return File.absolutePath as a String and keep @Input.
    
    Please refer to https://docs.gradle.org/7.4/userguide/validation_problems.html#incorrect_use_of_input_annotation for more details about this problem.

* 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.
==============================================================================

2: Task failed with an exception.
-----------
* What went wrong:
A problem was found with the configuration of task ':unityLibrary:compileDebugShaders' (type 'ShaderCompile').
  - In plugin 'com.android.build.gradle.api.AndroidBasePlugin' type 'com.android.build.gradle.tasks.ShaderCompile' property 'sourceDir' is annotated with @InputFiles but missing a normalization strategy.
    
    Reason: If you don't declare the normalization, outputs can't be re-used between machines or locations on the same machine, therefore caching efficiency drops significantly.
    
    Possible solution: Declare the normalization strategy by annotating the property with either @PathSensitive, @Classpath or @CompileClasspath.
    
    Please refer to https://docs.gradle.org/7.4/userguide/validation_problems.html#missing_normalization_annotation for more details about this problem.

* 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.
==============================================================================

3: Task failed with an exception.
-----------
* What went wrong:
Some problems were found with the configuration of task ':unityLibrary:transformNativeLibsWithMergeJniLibsForDebug' (type 'TransformTask').
  - In plugin 'com.android.build.gradle.api.AndroidBasePlugin' type 'com.android.build.gradle.internal.pipeline.TransformTask' property 'allSecondaryInputs' is private and annotated with @Internal.
    
    Reason: Annotations on private getters are ignored.
    
    Possible solutions:
      1. Make the getter public.
      2. Annotate the public version of the getter.

作为非专业安卓工程师,我根本就看不懂报错,只知道和“com.android.build.gradle.api.AndroidBasePlugin”脱不了干系,然后紧接着发现AS在建议我升级一些配置,看样子是要升级什么东西。
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-RGcVC7Aj-1688017256810)(C:UsersgyAppDataLocalTemp企业微信截图_1687940470251.png)]

神奇的事情发生了,我点击升级后,打包成功了,然后接着我发现他升级的东西就是gradle里面定义的一个依赖版本。

2.gradle android plugin 版本需要升级:

​ 3.4.0 => 4.2.0
​ 此时需要修改gradle里面的依赖,改gradle的文件需要处理一个问题,Unity的Custom Gradle有几种,如果修改错误可能会导致报错:
[Could not find method classpath() for arguments [com.android.tools.build:gradle:4.0.0]

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-vvtR12aI-1688017256811)(C:UsersgyAppDataRoamingTyporatypora-user-imagesimage-20230627143844398.png)]

第二种修改方法:直接修改UnityEditor文件下的gradle文件
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-66sOBv1Y-1688017256811)(file:///C:/Users/gy/Documents/WXWork/1688850302849244/Cache/Image/2023-06/企业微信截图_16879176944369.png)]

感恩戴德出包了!

装上包,NMD闪退了

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-sRkflf41-1688017256811)(C:UsersgyAppDataRoamingTyporatypora-user-imagesimage-20230628170748477.png)]

2023/06/28 16:38:56.105 4912 4979 Error Unity The file ‘/data/app/~~9dlUytlV0Q8idFcjL1iVkA==/com.lmd.dev.xproject-x4dpKkGPp7G8SwWpLHuc4g==/base.apk/assets/bin/Data/ea726188743d68d45b5a458307e424f8’ is corrupted! Remove it and launch unity again!

继续解决问题:
网上根本搜不到关于Fascebook是如何处理这个问题的。看样子就是facebook初始化报错了,网上的各种解决办法都千奇百怪。

我重新打包报错是一样的,然后拆包查看那个资源文件,文件一大堆乱码,但是有个Facebooksetting字眼,该文件是记录AppID等信息的一个asset,且文件的位置在Resources下面,恰好网上有说asset问题的,有说Resources文件夹问题的,我只能一一都试一试。关键是我手动打包是不会报错闪退的,tmd。

Script attached to ‘FacebookSettings’ in scene ‘’ is missing or no valid script is attached.

改meta冲突解决的
In my case I found that the meta file for the script was checked in in a conflicted state. The team uses SVN, so the left right and working copies were all in there. I manually fixed the meta file and it seems to have worked. You could probably also just delete the meta file and let unity regenerate it, but the guid would probably change, which is why I opted for doing it manually.

删除丢失脚本引用的
I got this error after deleting some scripts but not deleting some prefabs that used those scripts. Even though those prefabs are not being used anywhere, they generated those warnings during builds. Check your prefabs for missing script references and delete them (or remove the script component)

有ScriptableObject的asset文件和cs文件同名的(这个存疑,因为FB的package默认命名就是这样的,demo也出包成功了的)
I had kind of the same error, but I had a ScriptableObject class called Item, but the filename was Items.cs - then I got this error. Had to rename the file to Item.cs

手动打包发现console面板有个日志叫我 regenerate AndroidMenifist 文件,于是我点击后出的包初始化FBSDK就会成功,于是乎需要处理的是在自动打包流程里面需要处理这件事情。