Titanium JIRA Archive
Appcelerator Community (AC)

[AC-1735] Unable to integrate Android Library project with Titanium Module

GitHub Issuen/a
TypeBug
Priorityn/a
StatusClosed
ResolutionFixed
Resolution Date2012-10-10T21:16:53.000+0000
Affected Version/sn/a
Fix Version/sn/a
Componentsn/a
Labelsn/a
ReporterPerminder Singh Bhatia
AssigneeShak Hossain
Created2012-10-03T11:51:35.000+0000
Updated2016-03-08T07:40:37.000+0000

Description

We are in a process to develop a module for an SDK. As per the documentation of the SDK, to use it in an android native project we have to include an extra Android Native Library Project provided with SDK. In order to develop the Titanium Module for this SDK, i have currently consumed all methods exposed by SDK and have exposed it to javascript interface(app.js) using @Kroll Annotations. Now, the problem is that in order to make my module work, how should i proceed to include the Android Native Library project provided with SDK in my Titanium Module as this is required by SDK to work. I have found no documentation for the same on developer.appcelerator.com and got no results googling for the same. I tried copying contents of Android Library Project to module folders but it is not working and i get java.lang.NullPointerException during runtime when activity of Android Library Project is invoked while using this module in a Titaniun Application. Following are the steps followed to copy contents of Android Library Project to Titanium Module directories: 1. src folder contents of library project copied to src folder of module project 2. res folder contents of library project copied to platform/android/res folder of module project 3. Entries from tag of AndroidManifest.xml of library project copied to tag of timodule.xml Please help as this is a blocker in implementing Titanium Android Module for the SDK

Attachments

FileDateSize
sample_apklib_module.zip2012-10-09T12:33:35.000+00001662051
Sample_Test_apklib.zip2012-10-09T12:33:35.000+0000159494
Sample-apklib.zip2012-10-09T12:33:35.000+000082653

Comments

  1. Pedro Enrique 2012-10-08

    Please take a look at Step two of [this Guide](https://wiki.appcelerator.org/display/guides2/Android+Module+Development+Guide)
       lib - Place any third party JAR dependencies here and they will be bundled up as a part of your module automatically.
       
  2. Perminder Singh Bhatia 2012-10-09

    @Pedro - I am not bundling a third party jar to use some of its classes and methods in my module but what i am trying to use is a android library project having activities which are using custom layouts
  3. Perminder Singh Bhatia 2012-10-09

    I am adding three files explaining my issue: 1. Sample-apklib.zip: This is the Sample Android Library project i am using in my Sample Android Native Project and want to use with my Sample Titanium Android Module 2. Sample_Test_apklib.zip: This is the Sample Android Native Project using Sample Android Library Project 3. sample_apklib_module.zip: This is the Sample Titanium Android Module in which i am using Sample Android Library Project ======= ISSUE: ======= When i run my Titanium Module and call library project's activity using invoke button defined in test harness "example/app.js", i get following error on android log and my application crashes: E/TiApplication( 591): (main) [110,2497] Sending event: exception on thread: main msg:java.lang.NoClassDefFoundError: sample.test.apklib.R$layout; Titanium 2.1.3,2012/10/02 16:16,15997d0 E/TiApplication( 591): java.lang.NoClassDefFoundError: sample.test.apklib.R$layout E/TiApplication( 591): at sample.test.apklib.SampleApklibActivity.init(SampleApklibActivity.java:37) E/TiApplication( 591): at sample.test.apklib.SampleApklibActivity.onCreate(SampleApklibActivity.java:22) E/TiApplication( 591): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) E/TiApplication( 591): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627) E/TiApplication( 591): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679) E/TiApplication( 591): at android.app.ActivityThread.access$2300(ActivityThread.java:125) E/TiApplication( 591): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033) E/TiApplication( 591): at android.os.Handler.dispatchMessage(Handler.java:99) E/TiApplication( 591): at android.os.Looper.loop(Looper.java:123) E/TiApplication( 591): at android.app.ActivityThread.main(ActivityThread.java:4627) E/TiApplication( 591): at java.lang.reflect.Method.invokeNative(Native Method) E/TiApplication( 591): at java.lang.reflect.Method.invoke(Method.java:521) E/TiApplication( 591): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) E/TiApplication( 591): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) E/TiApplication( 591): at dalvik.system.NativeStart.main(Native Method) E/AndroidRuntime( 591): FATAL EXCEPTION: main E/AndroidRuntime( 591): java.lang.NoClassDefFoundError: sample.test.apklib.R$layout E/AndroidRuntime( 591): at sample.test.apklib.SampleApklibActivity.init(SampleApklibActivity.java:37) E/AndroidRuntime( 591): at sample.test.apklib.SampleApklibActivity.onCreate(SampleApklibActivity.java:22) E/AndroidRuntime( 591): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) E/AndroidRuntime( 591): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627) E/AndroidRuntime( 591): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679) E/AndroidRuntime( 591): at android.app.ActivityThread.access$2300(ActivityThread.java:125) E/AndroidRuntime( 591): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033) E/AndroidRuntime( 591): at android.os.Handler.dispatchMessage(Handler.java:99) E/AndroidRuntime( 591): at android.os.Looper.loop(Looper.java:123) E/AndroidRuntime( 591): at android.app.ActivityThread.main(ActivityThread.java:4627) E/AndroidRuntime( 591): at java.lang.reflect.Method.invokeNative(Native Method) E/AndroidRuntime( 591): at java.lang.reflect.Method.invoke(Method.java:521) E/AndroidRuntime( 591): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) E/AndroidRuntime( 591): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) E/AndroidRuntime( 591): at dalvik.system.NativeStart.main(Native Method) I hope this explains the situation in detail. Please provide a solution as my delivery is stuck because of this issue.
  4. Pedro Enrique 2012-10-09

    I'm not too sure what you're trying to do, but here are two resources you can look into: - http://developer.appcelerator.com/question/121573/how-do-i-use-so-library-in-module - http://developer.appcelerator.com/blog/2011/01/titanium-and-the-android-ndk.html
  5. Anirudh Nagesh 2012-10-10

    @Perminder: Looks like its a bug in our module build scripts. I was able to figure it out after some research. Below is whats happening. If you include any android native library with UI objects build using xml and reference it using R.id.XXX ( as you do it in android ) , our build scripts dont recognize it and throws ClassNotFoundException for R.Java. Here is what you need to do ---------------------------- 1. Make the following changes in your 'SampleApklibActivity.java'.
        //ViewGroup mainView = (ViewGroup) inflater.inflate(R.layout.apklib, null);
       		//Log.e("##CHECKMOD", "mainView: " + String.valueOf(mainView));
       		final Activity act = this;
       		//Button btn = (Button) mainView.findViewById(R.id.clickToMessage);
       		Button btn = new Button(this);
       		btn.setOnClickListener(new View.OnClickListener() {
       
       			@Override
       			public void onClick(View v) {
       				CharSequence str = new String("********** Quick Message ************");
       				Log.i("##CHECKMOD", str.toString());
       
       			}
       		});
       
       		//this.addContentView(mainView, lp);
       		this.setContentView(btn);
       
    Note that i have just created a button with normal java widget and add that to the view. 2. Build the application as normal android application ( Uncheck the 'Is Library' checkbox under project properties->Android ). This is just to see if you can see a button and click works. 3. Build it as a library ( Check the 'Is library' option by right clicking the project -> properties -> Android ). Clean and build. A jar file should be generated under bin folder of sample.test.apklib.SampleApklibAcitivity project. 4. Copy the above jar file to 'lib' folder of your module project which is sample_apk_lib_module. Also include the same jar file in your module project build path as an external jar or a library. If you are including as a library, include as user library. Adding a user library is pretty easy with eclipse dialogs. 5. Now run the following commands in the terminal from the project path.
       ant clean // to clean the project
       ant //to build. should not see any errors.
       ant run.emulator //to instantiate an android emulator
       ant run //to run the app
       
    6. Or run the example app the traditional way by unzipping the module to titanium root folder and including it in tiapp.xml in the ti project. Hope it helps. Regards, Anirudh ```
  6. Perminder Singh Bhatia 2012-10-10

    @Anirudh- Thanks a lot and i really appreciate that you understood my problem to its core and the workaround you provide will very well fit in the samples provided. But, this was just a small slice of a large cake. In current scenario i have to integrate a Library Project provided with a third party Android SDK (which i am exposing through Titanium Module) whose activity has a large number of UI elements which are difficult to program in code as there is a very high risk of breaking its UI. Though i will try changing code of the Library Project to test the workaround but, is there any possibility that a patch can be provided to me to fix this bug and i do not have to modify the code? Thanks & Regards, Perminder
  7. Anirudh Nagesh 2012-10-10

    @Perminder: I understand the criticality and your need. I will create a jira ticket for the same and update the same here. But, I believe it should not be difficult to implement all your UI elements in java ( if the UI is not complicated ).
  8. Anirudh Nagesh 2012-10-10

  9. Anirudh Nagesh 2012-10-10

    Jira created
  10. Perminder Singh Bhatia 2012-10-11

    @Anirudh - Thanks a lot for your support. The UI is pretty complex and carries high risk of breaking if coded. I will wait on the ticket (TIMOB-11360) for resolution and hope to get it as early as possible. Thanks & Regards, Perminder

JSON Source