在钛中,是否可以从 android 模块访问 3rd-party-jar-bundled 资源文件( xml )?
in titanium, is it possible to access the 3rd-party-jar-bundled resource files( xml ) from an android module?
我一直在研究如何访问 3rd-party-jar-bundled 资源 文件(xml 文件、图像、引用 here )来自 android 模块。可以这样做吗?
因为这些资源文件被编译后的第 3 方 jar 文件调用,这意味着我无法在本机 java 代码中使用 TiRHelper.getApplicationResource
方法,除非我:
- 将 jar 文件反编译为 java 代码。
- 将所有本机资源引用替换为 TiRHelper.getApplicationResource
- 将第 3 方 java 源代码重新编译为 jar 文件。
(这个第三方工程是https://github.com/ShareSDKPlatform/ShareSDK-for-Android/tree/master/Sample,我可以轻松编译&运行它。你可以看到/res文件夹中有资源文件,其中一个jar文件使用了这些资源文件。)
找了一整天也没找到答案。
从官方document那里得到了一些线索,试过了没有成功。该错误表明该资源不是来自 titanium 模块的 java 代码的 accessbile。
另外,同样的问题 (http://developer.appcelerator.com/question/178857/unable-to-load-resources-from-3rd-party-librarys-resourced-in-android-module) 没有得到回答。
这个答案(http://developer.appcelerator.com/question/49671/android-r-references-in-appcelerator-module#answer-266726)给了我一个线索,方法是:
getResource() gives an Error
getAndroidResource() gives an Error
but getApplicationResource() DOES work
并且有线索表明 'apklib' 可能有用,但是在阅读一些帖子后,我发现它已从 maven 官方网站上删除。现在 Google 建议改用 'aar' 文件。但是根据this Titanium official issue (https://jira.appcelerator.org/browse/TIMOB-18565 ),它还没有被titanium支持。
所以,我想知道,是否可以让 java 代码(例如 activity)访问其 3rd-party-jar-bundled 资源文件(value/string .xml 左右 ) 来自 Titanium 模块?如果是这样,有没有我可以参考的示例代码?
非常感谢!
根据新信息更新。要让它工作,您只需要将 github 中的 res 文件夹合并到您的 platforms/android/res 文件夹中。然后当你正常编译你的模块时。
===========================
如果您从 java 中的模块内部访问,请尝试使用
TiRHelper.getApplicationResource 为您提供的东西。
例如,如果您添加了:
platforms/android/values/strings.xml
你好!
电话会是
TiRHelper.getApplicationResource("string.helloworld");
如果您觉得这有帮助,请投票。如果不让我知道,我可以调整。
(快速简短的回答:将资源文件作为 "Titanium" 项目的一部分,但不要将它们放入 "module"。如果您坚持将它们放入 "module" , 请继续阅读。)
终于,我得到了答案。
官方文档是正确的,只是将3rd-party-jar的资源文件(原生android项目的res
文件夹)放在titanium模块的android/platform/android
文件夹下。而已!
例如我的模块工程结构如下图:
# name: test_ti_module_qq_login:
android
\--assets
\--build
\--dist
\--lib
\--libs
\--src
\--platform
\--android
\--res # just put the resources here in your module!
\--drawable
\--drawable-hdpi
\--drawable-xhdpi
\--layout
\--values
assets
documentation
example
LICENSE
...
仅供参考,本机 android 资源文件夹如下所示:
# A native Android project structure
▸ assets/
▸ bin/
▸ gen/
▸ libs/
▾ res/ # these are the bundled resource files
▸ drawable-hdpi/
▸ drawable-xhdpi/
▸ layout/
▸ values/
▸ src/
Titanium 一直显示resource files missing
的根本原因是我错过了一些资源文件。 (但是有点直接,本机代码演示可以 运行 没有错误,无论如何,最后我得到了解决方案)
加法:
好像很多人遇到了同样的问题?这几天我会开源我的项目。
我一直在研究如何访问 3rd-party-jar-bundled 资源 文件(xml 文件、图像、引用 here )来自 android 模块。可以这样做吗?
因为这些资源文件被编译后的第 3 方 jar 文件调用,这意味着我无法在本机 java 代码中使用 TiRHelper.getApplicationResource
方法,除非我:
- 将 jar 文件反编译为 java 代码。
- 将所有本机资源引用替换为 TiRHelper.getApplicationResource
- 将第 3 方 java 源代码重新编译为 jar 文件。
(这个第三方工程是https://github.com/ShareSDKPlatform/ShareSDK-for-Android/tree/master/Sample,我可以轻松编译&运行它。你可以看到/res文件夹中有资源文件,其中一个jar文件使用了这些资源文件。)
找了一整天也没找到答案。
从官方document那里得到了一些线索,试过了没有成功。该错误表明该资源不是来自 titanium 模块的 java 代码的 accessbile。
另外,同样的问题 (http://developer.appcelerator.com/question/178857/unable-to-load-resources-from-3rd-party-librarys-resourced-in-android-module) 没有得到回答。
这个答案(http://developer.appcelerator.com/question/49671/android-r-references-in-appcelerator-module#answer-266726)给了我一个线索,方法是:
getResource() gives an Error
getAndroidResource() gives an Error
but getApplicationResource() DOES work
并且有线索表明 'apklib' 可能有用,但是在阅读一些帖子后,我发现它已从 maven 官方网站上删除。现在 Google 建议改用 'aar' 文件。但是根据this Titanium official issue (https://jira.appcelerator.org/browse/TIMOB-18565 ),它还没有被titanium支持。
所以,我想知道,是否可以让 java 代码(例如 activity)访问其 3rd-party-jar-bundled 资源文件(value/string .xml 左右 ) 来自 Titanium 模块?如果是这样,有没有我可以参考的示例代码?
非常感谢!
根据新信息更新。要让它工作,您只需要将 github 中的 res 文件夹合并到您的 platforms/android/res 文件夹中。然后当你正常编译你的模块时。
===========================
如果您从 java 中的模块内部访问,请尝试使用 TiRHelper.getApplicationResource 为您提供的东西。
例如,如果您添加了:
platforms/android/values/strings.xml 你好!
电话会是
TiRHelper.getApplicationResource("string.helloworld");
如果您觉得这有帮助,请投票。如果不让我知道,我可以调整。
(快速简短的回答:将资源文件作为 "Titanium" 项目的一部分,但不要将它们放入 "module"。如果您坚持将它们放入 "module" , 请继续阅读。)
终于,我得到了答案。
官方文档是正确的,只是将3rd-party-jar的资源文件(原生android项目的res
文件夹)放在titanium模块的android/platform/android
文件夹下。而已!
例如我的模块工程结构如下图:
# name: test_ti_module_qq_login:
android
\--assets
\--build
\--dist
\--lib
\--libs
\--src
\--platform
\--android
\--res # just put the resources here in your module!
\--drawable
\--drawable-hdpi
\--drawable-xhdpi
\--layout
\--values
assets
documentation
example
LICENSE
...
仅供参考,本机 android 资源文件夹如下所示:
# A native Android project structure
▸ assets/
▸ bin/
▸ gen/
▸ libs/
▾ res/ # these are the bundled resource files
▸ drawable-hdpi/
▸ drawable-xhdpi/
▸ layout/
▸ values/
▸ src/
Titanium 一直显示resource files missing
的根本原因是我错过了一些资源文件。 (但是有点直接,本机代码演示可以 运行 没有错误,无论如何,最后我得到了解决方案)
加法:
好像很多人遇到了同样的问题?这几天我会开源我的项目。