Can't find resource symbol from plugin (Android)

Hi,

I have an image that I put inside my resource/drawable and I used to be able to access by its ID in the application class easily like this : R.drawable.rec_id

But when I try to use it inside my LuaLoader class the compiler says symbol not found? I already import android.R and everything

I’m curious with the way enterprise compile as it seems Lualoader class is compiled before R.java is generated?

Looking at the R.java, my resource id does exist so I’m not sure if anything from resource is accessible from LuaLoader class?

Help pls?

Thanks

Can you post an example (code) of what you are doing?

Thanks

Hmm… I really don’t know what’s the best way to do show you what I’m doing since there’s only one troubled code and posting my whole LuaLoader class will be too long?

So this is the code inside the LuaLoader class that I do :

mController.setShareMedia(new UMImage(CoronaEnvironment.getCoronaActivity(),R.drawable.kqpromo));  

I don’t think we need the context of what the code is since this is just a piece of code to use UMeng Socmed SDK. The problem is that compiler says can’t find symbol R.drawable.kqpromo

While I checked my R.java and found the symbol :

 public static final class drawable {         public static final int corona\_statusbar\_icon\_default=0x7f020000;         public static final int ic\_maps\_indicator\_current\_position=0x7f020001;         public static final int ic\_maps\_indicator\_current\_position\_anim1=0x7f020002;         public static final int ic\_maps\_indicator\_current\_position\_anim2=0x7f020003;         public static final int ic\_maps\_indicator\_current\_position\_anim3=0x7f020004;         public static final int ic\_menu\_camera=0x7f020005;         public static final int ic\_menu\_refresh=0x7f020006;         public static final int icon=0x7f020007;         public static final int kqpromo=0x7f020008;  

I don’t really understand how the Lualoader class works though since I’m quite noob in native Android development but so far I learned that this symbol isn’t recognizable from LuaLoader class but recognizable in my coronapplication class

ps : I already do the necessary import android.R

Thanks

I googled, but couldn’t find any reference to the “UMeng Socmed SDK”.

Could you provide me with a link ?

http://dev.umeng.com/en/umeng-share/umeng-share-android/share/share-quick-guide

Thanks.

Do you want to email me your project and I can take a proper look and cut out the guess work?

danny [at] coronalabs [dot] com

Thanks

LuaLoader?  Are you building a JAR file and then dropping it into the “libs” directory in a different Android project?

If so, then what you’re trying to do isn’t possible with Google’s Android build system.  The reason is because the Android build system creates an “R.java” file via code generation every time you rebuild your app.  Every resource under your “res” directory also gets assigned a unique integer ID, which is the ID you are using in your code, but those IDs are only unique for that build.  So, if you do separate builds for your JAR file and your application, then you’ll have conflicting resource IDs in their R.java files.  The proof is in your Android project’s “gen” directory because that is where your R.java file gets generated.  If you look at the source code for both projects, you’ll find that they use the same integer IDs for different resources.  There lies your problem.

If you do not intend on making a plugin for other Corona developers to you, then my advise is to keep it simple and not bother in building a separate JAR file.  It is simpler to add all of your Lua extensions to your main application’s code as shown in Corona Enterprise sample project “SimpleLuaExtensions”.

If your intention is to create Corona plugin, then unfortunately resources are not supported for the reasons I’ve mentioned above.

Anyways, I hope this helps.

Thanks Danny, 

Sent you a mail just now

Joshua,

That’s what I’m afraid of, I’m not trying to create a plugin for other developer but I like the approach of making my own plugin instead of having a function in my main application.

Reason being is that I have a social media functionality that I need to implement and it can be called from any part of my corona project (lua module). I also read about this :

"Native extensions

For your convenience, the projects are structured so that your extensions are packaged as plugins. In both the iOS and Android version of the App project, the Lua library plugin.library is created."

I also vaguely remember that sample “SimpleLuaExtensions” is deprecated : [http://docs.coronalabs.com/legacy/native/android/index.html#deprecated-examples

T](http://docs.coronalabs.com/legacy/native/android/index.html#deprecated-examples)hat’s why I put my functionality in the LuaLoader class and use that approach. Is this the best approach?

Oh no.  That “SimpleLuaExtensions” sample project is certainly *not* deprecated.  I’m going to have to flog the person who wrote that.  I personally wrote all of the Enterprise sample projects for Android, kept them up to date, and they’re by far the simplest most well documented examples that we’ve got.  The “App” template is intended for plugin developers.  I’m so sorry for the confusion.

If you want to make your social media a separate Android library and avoid the resource issue, then the solution is to create an “Android library project”.  This has a very particular directory structure which would look a lot like the Corona or Facebook Android library folders.  If you do it this way, then all you have to do is reference your library project via the “project.properties” file.  Then when you build your application project, the Android build system will merge the resource files from all the library projects and the application project into one and generate a single “R.java” file for all projects, avoiding the duplicate resource ID issue.

Google documents how to set up Android library projects here…

   https://developer.android.com/tools/projects/index.html#LibraryProjects

<p>Don’t flog the guy, have mercy <img class=“bbc_emoticon” src=“http://forums.coronalabs.com/public/style_emoticons/default/smile.png” title=":)" /></p>
<p> </p>
<p>Anyway, it doesn’t take much for me to change from LuaLoader but the problem still the same. Here’s my class, it’s abit long but you only need to care about public function show() where I need to access R.drawable.kqpromo :<br />
 </p>

<p>“UMImage(CoronaEnvironment.getCoronaActivity(),R.drawable.kqpromo));” -> Still cause problem cause the symbol R.drawable.kqpromo isn’t found.<br />
<br />
Sorry if the code is too long but I don’t want to leave anything out.</p>

I think the problem is with your “import android.R;” statement.

The Android build system will generate an “R.java” file under the package name (aka: namespace) you specified in your “AndroidManifest.xml” file.  That’s the one you need to import because it contains your app’s resource constants.

Assuming that your package name is “com.iplayalldaystudio.kqiplay”, try changing your import statement to this…

   import com.iplayalldaystudio.kqiplay.R;

…or if your Java code is already in the “com.iplayalldaystudio.kqiplay” package/namspace, then you don’t need to import the “R” class at all.

That solved it! Thanks Joshua for the support though it has more to do with me being a noob android coder rather than an enterprise issue.

I really appreciate it, my lingering question is… using packagename.R didn’t work before and consult in stackoverflow and someone suggest that android.R is the right way to do.

Nvm… will read the docs later but at least now it’s working :slight_smile:

Happy to help!  Oh and the “android.R” class that you imported belongs to Google and is what’s documented in the link below.  That’s definitely not the one you wanted.  :slight_smile:

   http://developer.android.com/reference/android/R.html

Can you post an example (code) of what you are doing?

Thanks

Hmm… I really don’t know what’s the best way to do show you what I’m doing since there’s only one troubled code and posting my whole LuaLoader class will be too long?

So this is the code inside the LuaLoader class that I do :

mController.setShareMedia(new UMImage(CoronaEnvironment.getCoronaActivity(),R.drawable.kqpromo)); &nbsp;

I don’t think we need the context of what the code is since this is just a piece of code to use UMeng Socmed SDK. The problem is that compiler says can’t find symbol R.drawable.kqpromo

While I checked my R.java and found the symbol :

&nbsp;public static final class drawable { &nbsp; &nbsp; &nbsp; &nbsp; public static final int corona\_statusbar\_icon\_default=0x7f020000; &nbsp; &nbsp; &nbsp; &nbsp; public static final int ic\_maps\_indicator\_current\_position=0x7f020001; &nbsp; &nbsp; &nbsp; &nbsp; public static final int ic\_maps\_indicator\_current\_position\_anim1=0x7f020002; &nbsp; &nbsp; &nbsp; &nbsp; public static final int ic\_maps\_indicator\_current\_position\_anim2=0x7f020003; &nbsp; &nbsp; &nbsp; &nbsp; public static final int ic\_maps\_indicator\_current\_position\_anim3=0x7f020004; &nbsp; &nbsp; &nbsp; &nbsp; public static final int ic\_menu\_camera=0x7f020005; &nbsp; &nbsp; &nbsp; &nbsp; public static final int ic\_menu\_refresh=0x7f020006; &nbsp; &nbsp; &nbsp; &nbsp; public static final int icon=0x7f020007; &nbsp; &nbsp; &nbsp; &nbsp; public static final int kqpromo=0x7f020008; &nbsp;

I don’t really understand how the Lualoader class works though since I’m quite noob in native Android development but so far I learned that this symbol isn’t recognizable from LuaLoader class but recognizable in my coronapplication class

ps : I already do the necessary import android.R

Thanks

I googled, but couldn’t find any reference to the “UMeng Socmed SDK”.

Could you provide me with a link ?

http://dev.umeng.com/en/umeng-share/umeng-share-android/share/share-quick-guide

Thanks.

Do you want to email me your project and I can take a proper look and cut out the guess work?

danny [at] coronalabs [dot] com

Thanks

LuaLoader?  Are you building a JAR file and then dropping it into the “libs” directory in a different Android project?

If so, then what you’re trying to do isn’t possible with Google’s Android build system.  The reason is because the Android build system creates an “R.java” file via code generation every time you rebuild your app.  Every resource under your “res” directory also gets assigned a unique integer ID, which is the ID you are using in your code, but those IDs are only unique for that build.  So, if you do separate builds for your JAR file and your application, then you’ll have conflicting resource IDs in their R.java files.  The proof is in your Android project’s “gen” directory because that is where your R.java file gets generated.  If you look at the source code for both projects, you’ll find that they use the same integer IDs for different resources.  There lies your problem.

If you do not intend on making a plugin for other Corona developers to you, then my advise is to keep it simple and not bother in building a separate JAR file.  It is simpler to add all of your Lua extensions to your main application’s code as shown in Corona Enterprise sample project “SimpleLuaExtensions”.

If your intention is to create Corona plugin, then unfortunately resources are not supported for the reasons I’ve mentioned above.

Anyways, I hope this helps.

Thanks Danny, 

Sent you a mail just now

Joshua,

That’s what I’m afraid of, I’m not trying to create a plugin for other developer but I like the approach of making my own plugin instead of having a function in my main application.

Reason being is that I have a social media functionality that I need to implement and it can be called from any part of my corona project (lua module). I also read about this :

"Native extensions

For your convenience, the projects are structured so that your extensions are packaged as plugins. In both the iOS and Android version of the App project, the Lua library plugin.library is created."

I also vaguely remember that sample “SimpleLuaExtensions” is deprecated : [http://docs.coronalabs.com/legacy/native/android/index.html#deprecated-examples

T](http://docs.coronalabs.com/legacy/native/android/index.html#deprecated-examples)hat’s why I put my functionality in the LuaLoader class and use that approach. Is this the best approach?