我目前正在将Android库转换为Unity插件.
我已经走了很长的路,但是现在我已经陷入无法从Unity访问图书馆资源的地步.
应用程序运行正常,直到我实际从库中调用视图.
这是我在那一刻得到的错误日志:
12-12 13:37:36.495: W/ResourceType(32155): getEntry failing because entryIndex 1 is beyond type entryCount 1
12-12 13:37:36.495: W/ResourceType(32155): Failure getting entry for 0x7f030001 (t=2 e=1) in package 0 (error -2147483647)
12-12 13:37:36.500: D/AndroidRuntime(32155): Shutting down VM
12-12 13:37:36.500: W/dalvikvm(32155): threadid=1: thread exiting with uncaught exception (group=0x4109a2a0)
12-12 13:37:36.505: E/AndroidRuntime(32155): FATAL EXCEPTION: main
12-12 13:37:36.505: E/AndroidRuntime(32155): android.content.res.Resources$NotFoundException: Resource ID #0x7f030001
12-12 13:37:36.505: E/AndroidRuntime(32155): at android.content.res.Resources.getValue(Resources.j ava:1026)
12-12 13:37:36.505: E/AndroidRuntime(32155): at android.content.res.Resources.loadXmlResourceParse r(Resources.java:2131)
12-12 13:37:36.505: E/AndroidRuntime(32155): at android.content.res.Resources.getLayout(Resources. java:865)
12-12 13:37:36.505: E/AndroidRuntime(32155): at android.view.LayoutInflater.inflate(LayoutInflater .java:394)
12-12 13:37:36.505: E/AndroidRuntime(32155): at android.view.LayoutInflater.inflate(LayoutInflater .java:352)
12-12 13:37:36.505: E/AndroidRuntime(32155): at com.mycompany.mylibrary.components.AndroidWebViewD ialog.<init>(AndroidWebViewDialog.java:140)
12-12 13:37:36.505: E/AndroidRuntime(32155): at com.mycompany.mylibrary.FunctionAndroidLibrary.Sho wDialog(FunctionAndroidLibrary.java:163)
12-12 13:37:36.505: E/AndroidRuntime(32155): at com.mycompany.mylibrary.FunctionAndroidLibrary.but tonREGISTER(FunctionAndroidLibrary.java:94)
12-12 13:37:36.505: E/AndroidRuntime(32155): at com.mycompany.myUnityProjectAndroidLibraryTest$1.r un(AndroidLibraryTest.java:78)
12-12 13:37:36.505: E/AndroidRuntime(32155): at android.os.Handler.handleCallback(Handler.java:615 )
12-12 13:37:36.505: E/AndroidRuntime(32155): at android.os.Handler.dispatchMessage(Handler.java:92 )
12-12 13:37:36.505: E/AndroidRuntime(32155): at android.os.Looper.loop(Looper.java:137)
12-12 13:37:36.505: E/AndroidRuntime(32155): at android.app.ActivityThread.main(ActivityThread.jav a:4898)
12-12 13:37:36.505: E/AndroidRuntime(32155): at java.lang.reflect.Method.invokeNative(Native Method)
12-12 13:37:36.505: E/AndroidRuntime(32155): at java.lang.reflect.Method.invoke(Method.java:511)
12-12 13:37:36.505: E/AndroidRuntime(32155): at com.android.internal.os.ZygoteInit$MethodAndArgsCa ller.run(ZygoteInit.java:1006)
12-12 13:37:36.505: E/AndroidRuntime(32155): at com.android.internal.os.ZygoteInit.main(ZygoteInit .java:773)
12-12 13:37:36.505: E/AndroidRuntime(32155): at dalvik.system.NativeStart.main(Native Method)
>这些资源实际存在于库.jar文件中.
>从Unity Android项目禁用setContentView()
有谁可以帮忙吗?
先感谢您!
[编辑]
我想我在这里发现了问题:
http://tools.android.com/recent/dealingwithdependenciesinandroidprojects
Important 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.
有谁知道与Unity3D一起解决这个问题的最佳解决方案是什么?
解决方法:
实际上它是由Unity3D的一个不合适的后期打包过程引起的.它在aapt生成包含资源id的R类之前生成dex文件.所以你没有机会依赖静态资源id.
我已经通过为Unity3D编写一个编辑器插件解决了这个问题.但我现在无法释放它,因为它有问题而我现在太忙了,无法修复它.
但由于你的问题是移植代码.我建议你改变你的资源加载代码在java中采用Unity3D引起的这个问题.
// context should be the activity of your unity3d application which raise the call to your plugin.
// Loading string
String myResstring = context.getResources().getString(
context.getResources().getIdentifier("sample_string",
"string",
context.getPackageName()));
// Loading image
AlertDialog.Builder tDialog = new AlertDialog.Builder(context);
tDialog.setIcon(
context.getResources().getIdentifier("sample_icon", "drawable", context.getPackageName())
);
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。