• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
Locked
0

Null values when using R.* Mechanism for Android ANE (AIR 4.0.0.1240)

Explorer ,
Dec 04, 2013 Dec 04, 2013

Copy link to clipboard

Copied

So I wanted to try out the new AIR 4.0 implementation of requesting resources in android native extensions using R.* instead of getResourceId.  When stepping through the native extension code, anytime the R.* is being used in the native android code it returns an id for the resource, but the resource comes back as null everytime.  I assume it is because the resource id is not correct for some reason.  I do not know if I am doing something wrong or not.  When unpackaging the apk, I could see that the resources are being included correctly in the right folder.

I had to make sure when I exported my jar file from my android project that I did not include the res or gen folders.  The gen folder contained the R.java file that is auto-built in the android project, and when packaging the apk would throw an error saying the R.class was already added.  So removing the gen folder fixed that.

Here is how I packaged my ANE

extension.xml:

<extension xmlns="http://ns.adobe.com/air/extension/4.0">

          <id>com.example.anesample</id>

          <versionNumber>1</versionNumber>

          <platforms>

                    <platform name="Android-ARM">

                              <applicationDeployment>

                                        <nativeLibrary>anesample.jar</nativeLibrary>

                                        <initializer>com.example.aneexample.NativeExtensionSample</initializer>

                                        <finalizer>com.example.aneexample.NativeExtensionSample</finalizer>

                              </applicationDeployment>

                    </platform>

          </platforms>

</extension>

platform.xml:

<platform xmlns="http://ns.adobe.com/air/extension/4.0">

          <packagedResources>

                    <packagedResource>

                              <packageName>com.example.anesample</packageName>

                              <folderName>Android-Resources</folderName>

                    </packagedResource>

          </packagedResources>

</platform>

ane build command:

adt -package -target ane NativeExtensionSample.ane extension.xml -swc NativeExtensionSample.swc -platform Android-ARM -platformoptions platform.xml Android-Resources -C Android .

Folder stucture:

extension.xml

platform.xml

NativeExtensionSample.swc

Android

     |__anesample.jar

           library.swf

Android-Resources

      |__values

           layout

           drawable

           etc.

           (rest of the resources from the android project res folder)

Note: I do have other ANE's included in the app that are built with older versions of AIR and do not use the new R.* mechanism.  I was wondering if that would cause issues or not as well.  (I will be doing tests soon that exclude these ane's)

TOPICS
Air beta

Views

1.6K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Adobe Employee , Dec 04, 2013 Dec 04, 2013

Hi cb_bkelley,

You mention that you had to manually make sure that R.class was not present in your exported jar. It seems you are using a standard Android project to build your jar.

Could you please use an "Android Library project" to build your jar? It would automatically make sure that your jar does not have R.class, apart from other important benefits like generating non-constant resource ids.

I would request you to please create your jar using an "Android Library project" and then share your re

...

Votes

Translate

Translate
Adobe Employee ,
Dec 04, 2013 Dec 04, 2013

Copy link to clipboard

Copied

Hi cb_bkelley,

You mention that you had to manually make sure that R.class was not present in your exported jar. It seems you are using a standard Android project to build your jar.

Could you please use an "Android Library project" to build your jar? It would automatically make sure that your jar does not have R.class, apart from other important benefits like generating non-constant resource ids.

I would request you to please create your jar using an "Android Library project" and then share your results. I hope things would work fine then.

Thanks,

Daman

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Dec 05, 2013 Dec 05, 2013

Copy link to clipboard

Copied

Sorry for the off topic, but could you tell me if the new resource system allows us to override resources packaged inside an ANE with one placed in a res named folder in the main app?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Dec 05, 2013 Dec 05, 2013

Copy link to clipboard

Copied

Hi Neverbirth,

The res folder is always qualified by the package name of the project, if the package name of the main app and the ANE is different then there are no chances of the conflicts or overriding.

I hope that helps.

-Nimisha

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Dec 05, 2013 Dec 05, 2013

Copy link to clipboard

Copied

To make it more clear, I added a picture as a resource for an ANE, that image was a placeholder, and then I tried to override it with a new image from my main app, no matter how I tried, if I had a "res" folder it seemed adt ignored it completely and wasn't packaged in the final APK. Whenever I need to modify that image in a new project I have to open the ANE with WinRAR or similar, and overwrite it from there. Isn't there any other way? Does the new resources system modify this situation?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 05, 2013 Dec 05, 2013

Copy link to clipboard

Copied

LATEST

That did it!  Thanks!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines