I have been working on how to access the 3rd-party-jar-bundled resource files ( xml files, images , referred here ) from an android module. Is it possible to do this?
Because these resource files are called by the compiled-3rd-party jar files, which means, I am not able to use TiRHelper.getApplicationResource
method in the native java code unless I:
(This third party project is https://github.com/ShareSDKPlatform/ShareSDK-for-Android/tree/master/Sample, I can easily compile & run it. You can see there are resource files in /res folder, and one of the jar files used these resource files. )
I searched a whole day but found no answer.
I got some clues from the official document , tried but not success. the error show that the resource is not accessbile by the java code from titanium module.
also, this same question( http://developer.appcelerator.com/question/178857/unable-to-load-resources-from-3rd-party-librarys-resourced-in-android-module ) is not answered.
this answer( http://developer.appcelerator.com/question/49671/android-r-references-in-appcelerator-module#answer-266726 ) gives me a clue that the methods:
getResource() gives an Error
getAndroidResource() gives an Error
but getApplicationResource() DOES work
and there is a clue that the 'apklib' may be useful, but after read some posts, I found it has been deleted from maven official website. and now Google recommends use 'aar' file instead. But according to this Titanium official issue (https://jira.appcelerator.org/browse/TIMOB-18565 ), it is not supported by titanium yet.
so, I want to know, is it possible to let the java code ( e.g. an activity) access its 3rd-party-jar-bundled resource files ( value/string.xml or so ) from Titanium module? if so, is there any sample code that I can refer to?
thank a lot!
(fast & short answer: put the resources files as part of your "Titanium" project, but not put them into the "module". If you insist putting them into the "module", read on.)
Finally, I got the answer.
The official document is correct, just put the 3rd-party-jar's resource files( res
folder of a native android project) under titanium module's android/platform/android
folder. that's it!
e.g. my module project structure is shown as below:
# 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
...
and FYI, the native android resource folder looks like:
# A native Android project structure
▸ assets/
▸ bin/
▸ gen/
▸ libs/
▾ res/ # these are the bundled resource files
▸ drawable-hdpi/
▸ drawable-xhdpi/
▸ layout/
▸ values/
▸ src/
The root cause that why Titanium kept showing the resource files missing
is that I missed some of the resource files. (but it's a bit straight that the native code demo could be run without errors, whatever, finally I got the solution )
addition:
It seems that many people met the same problem? I will open source my project in these days.
Updating with based on the new information. To get that to work you would just need to merge the res folder from github into your platforms/android/res folder. Then when you compile your module as normal.
===========================
If you're accessing from within the module in java, try using TiRHelper.getApplicationResource for things you're providing.
So for example if you've added:
platforms/android/values/strings.xml hello!
The call would be
TiRHelper.getApplicationResource("string.helloworld");
Class Srouce
Javadoc
If you've found this helpful, please up vote. If not let me know so I can adjust.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With