Unity安卓报错解决方法:android.content.res.Resources$NotFoundException
Posted wolf96
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Unity安卓报错解决方法:android.content.res.Resources$NotFoundException相关的知识,希望对你有一定的参考价值。
参考: https://forum.unity.com/threads/android-content-res-resources-notfoundexception.162246/ https://forum.unity.com/threads/resource-not-found.81943/ 原理是这样的 http://tools.android.com/recent/dealingwithdependenciesinandroidprojectsImportant change: We have changed the way Library Projects generate and package R classes: The R class is not packaged in the jar output of Library Projects anymore. Library Project do not generate the R class for Library Projects they depend on. Only main application projects generates the Library R classes alongside their own.
解决方法是这样的 Don't load resources based on their compile-time ID; use Activity.getResources().getIdentifier() to retrieve the ID instead.
之前这句话报错 setContentView(R.layout.*****); 改成这样完美解决 int layoutId = getResources().getIdentifier( " ***** " , "layout" , getPackageName()); System. out .println( "layOutid为++" + layoutId ); setContentView( layoutId );
总结 简单来说是因为eclipse生成的R不是Unity的R,里面ID对应不上,所以找不到资源 反编译了一下 setContentView(R.layout.*****); 生成的jar包,里面的结果是直接把资源ID写死进去 setContentView(23423455); 这样Unity的R肯定找不到eclipse里定义的资源
int layoutId = getResources().getIdentifier( " ***** " , "layout" , getPackageName()); setContentView( layoutId ); 这样做了的话,资源id是运行时动态获取的,所以肯定没问题
以上是关于Unity安卓报错解决方法:android.content.res.Resources$NotFoundException的主要内容,如果未能解决你的问题,请参考以下文章
Unity 报错之 打包安卓闪退 Could not allocate memory: System out of memory
错误记录Unity 安卓打包报错( Platform Android with graphics API OpenGLES3 is not supported with HDRP )