在钛,是否可以从Android模块访问第三方jar捆绑的资源文件(xml)?

Siw*_*申思维 20 resources android module titanium

我一直在研究如何从Android模块访问第三方jar捆绑的资源文件(xml文件,图像,这里提到).是否有可能做到这一点?

因为这些资源文件是由编译的第三方jar文件调用的,这意味着我无法TiRHelper.getApplicationResource在本机java代码中使用方法,除非我:

  1. 将jar文件解编译为java代码.
  2. 将所有本机资源引用替换为TiRHelper.getApplicationResource
  3. 将第三方java源代码重新编译为jar文件.

(这个第三方项目是https://github.com/ShareSDKPlatform/ShareSDK-for-Android/tree/master/Sample,我可以轻松编译和运行它.你可以看到/ res文件夹中有资源文件,一个jar文件使用这些资源文件.)

我搜索了一整天但没有找到答案.

我从官方文件中得到了一些线索,试过但没有成功.错误显示资源不是来自钛模块的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
Run Code Online (Sandbox Code Playgroud)

并且有一个线索,'apklib'可能有用,但在阅读了一些帖子后,我发现它已经从maven官方网站上删除了.现在Google推荐使用'aar'文件.但根据这个Titanium官方问题(https://jira.appcelerator.org/browse/TIMOB-18565),钛尚不支持.

所以,我想知道,是否有可能让java代码(例如一个活动)从Titanium模块访问其第三方jar捆绑的资源文件(value/string.xml左右)?如果是的话,有没有我可以参考的示例代码?

非常感谢!

Siw*_*申思维 9

(快速和简短的回答:将资源文件作为"Titanium"项目的一部分,但不要将它们放入"模块".如果你坚持将它们放入"模块",请继续阅读.)

最后,我得到了答案.

官方文档是正确的,只需将第三方jar的资源文件(res本机android项目的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
... 
Run Code Online (Sandbox Code Playgroud)

和FYI,本机android资源文件夹看起来像:

# A native Android project structure   
? assets/          
? bin/             
? gen/             
? libs/           
? res/     # these are the bundled resource files
  ? drawable-hdpi/     
  ? drawable-xhdpi/    
  ? layout/     
  ? values/    
  ? src/       
Run Code Online (Sandbox Code Playgroud)

Titanium继续显示的根本原因resource files missing 是我错过了一些资源文件.(但是有点直接,本机代码演示可以无误地运行,无论如何,最后我得到了解决方案)

加成:

似乎很多人遇到了同样的问题?这些天我会开源我的项目.