3

After reading a zillion posts on how to make a referenced library work with Android-Eclipse I must declare failure to run the provided sample tic-tac-toe, which is split into two projects TicTacToeLib (marked as library) and TicTacToeMain (which uses TicTacToeLib)

  1. I first imported created TicTacToeLib into Eclipse (File->New->Other->Android->Android sample project->TicTacToeLib)
  2. Then imported created TicTacToeMain into Eclipse (File->New->Other->Android->Android sample project->TicTacToeMain)
  3. Followed the instructions on the Android Developers site on how to setup and reference a library project

Here I encounter the first obstacle, because on one hand the site mentions that <user-library> should be used, but the example Manifest for TicTacToeMain does not contain any <uses-library> element.
Either way the example does not run.

Without <user-library> element the project does not even compile:

enter image description here

If I add the tictactoelib.jar to the build path manually (Add JARs...), which is not part of the instructed steps in the Android Developers page, the errors dissapear, only the warnings remain. Running the app exits with failure (" Unfortunately Tic Tac Toe Sample has stopped "):

04-08 16:05:24.762: E/dalvikvm(3741): Could not find class 'com.example.android.tictactoe.library.GameActivity', referenced from method com.example.android.tictactoe.MainActivity.startGame
04-08 16:05:24.762: W/dalvikvm(3741): VFY: unable to resolve const-class 17 (Lcom/example/android/tictactoe/library/GameActivity;) in Lcom/example/android/tictactoe/MainActivity;
04-08 16:05:24.767: D/dalvikvm(3741): VFY: replacing opcode 0x1c at 0x0002
04-08 16:05:24.877: V/PhoneStatusBar(166): setLightsOn(true)
04-08 16:05:24.937: D/gralloc_goldfish(3741): Emulator without GPU emulation detected.
04-08 16:05:25.017: I/Process(89): Sending signal. PID: 3741 SIG: 3
04-08 16:05:25.027: I/dalvikvm(3741): threadid=3: reacting to signal 3
04-08 16:05:25.037: I/dalvikvm(3741): Wrote stack traces to '/data/anr/traces.txt'
04-08 16:05:25.058: I/ActivityManager(89): Displayed com.example.android.tictactoe/.MainActivity: +1s368ms
04-08 16:05:25.317: W/NetworkManagementSocketTagger(89): setKernelCountSet(10013, 0) failed with errno -2
04-08 16:05:27.857: D/AndroidRuntime(3741): Shutting down VM
04-08 16:05:27.857: W/dalvikvm(3741): threadid=1: thread exiting with uncaught exception (group=0x409c01f8)
04-08 16:05:27.918: E/AndroidRuntime(3741): FATAL EXCEPTION: main
04-08 16:05:27.918: E/AndroidRuntime(3741): java.lang.NoClassDefFoundError: com.example.android.tictactoe.library.GameActivity
04-08 16:05:27.918: E/AndroidRuntime(3741):     at com.example.android.tictactoe.MainActivity.startGame(MainActivity.java:51)
04-08 16:05:27.918: E/AndroidRuntime(3741):     at com.example.android.tictactoe.MainActivity.access$0(MainActivity.java:50)
04-08 16:05:27.918: E/AndroidRuntime(3741):     at com.example.android.tictactoe.MainActivity$1.onClick(MainActivity.java:38)
04-08 16:05:27.918: E/AndroidRuntime(3741):     at android.view.View.performClick(View.java:3511)
04-08 16:05:27.918: E/AndroidRuntime(3741):     at android.view.View$PerformClick.run(View.java:14105)

Adding the following line to the TicTacToeMain manifest:

<uses-library android:name="com.example.android.tictactoe.library"/>

does not even launch the app:

[2013-04-08 19:13:03 - TicTacToeMain] Android Launch!
[2013-04-08 19:13:03 - TicTacToeMain] adb is running normally.
[2013-04-08 19:13:03 - TicTacToeMain] Performing com.example.android.tictactoe.MainActivity activity launch
[2013-04-08 19:13:03 - TicTacToeMain] Automatic Target Mode: using existing emulator 'emulator-5554' running compatible AVD 'Smartphone_ics'
[2013-04-08 19:13:03 - TicTacToeMain] Uploading TicTacToeMain.apk onto device 'emulator-5554'
[2013-04-08 19:13:03 - TicTacToeMain] Installing TicTacToeMain.apk...
[2013-04-08 19:13:06 - TicTacToeMain] Installation error: INSTALL_FAILED_MISSING_SHARED_LIBRARY
[2013-04-08 19:13:06 - TicTacToeMain] Please check logcat output for more details.
[2013-04-08 19:13:06 - TicTacToeMain] Launch canceled!

I tried other things, none solved the problem:

  • Changed the target TicTacToeMain version to 15, to 10
  • Added the TicTacToeLib as User Library in the build path
  • Created a libs folder for TicTacToeMain, and copied tictactoelib.jar, did not solve, imported the tictactoelib.jar uising Import..., no sugar

The reason I want this sample to work, besides understadning how to the mechnaism for referenced libraries work, is that I want to create a complex app, using many referenced libraries and if I cannot make this silly sample work, then I will not be able to.

One more point, adding the reference library project to TicTacToeMain:

enter image description here

It does not stick, I press Apply as instructed, then OK. But when I open the Project's properties again (no run, no compile, just reopen):

enter image description here

Maybe this is the real symptom, but I don't know what else to try. I use Eclipse 4.2.1, Android SDK 21.1, Java IDE 1.5.1
Target Java Compliance level is 1.6
I tried several AVDs emulators, all show the same problem.

ilomambo
  • 8,290
  • 12
  • 57
  • 106

3 Answers3

0

It is just to do a new-project-android->Android Sample Project->Tictactoemain/lib. Do not import, just a new project and it works. In any case right click on project name -> Android Tools -> Fix Project Properties and in the menu Project-> Clean. Maybe another clean workspace or new emulator device (is it correctly setup?)? You have all java, android sdk, adt and so on? I have no such problems.

42n4
  • 1,292
  • 22
  • 26
  • I did RightClick->Android Tools->Fix Project, then Project clean, but same result. It did not fix the problem. I wrote `import` but if you read afterthat you see I created new projects. – ilomambo Apr 08 '13 at 17:31
  • Since you have no such problems, can you tell me which steps did you do to reference the library from TicTacToeMain? Which versions of Eclipse-Android SDK do you use? – ilomambo Apr 08 '13 at 19:09
  • Eclipse kepler http://www.eclipse.org/downloads/index-developer.php sdk 4.2 the newest one – 42n4 Apr 08 '13 at 19:55
0

about the reference library

This error means that your TicTacToLib is using from another project, to solve this error you have to :

  • copy the tictactolib.

  • delete that project which is using the tictactolib and check the remove from the hard disk.

  • past the tictactolib to the old path.

try again and the error will be gone.

Note:

ofc, you can just un import the library from the project which is using it right now without deleting that project.
William Kinaan
  • 28,059
  • 20
  • 85
  • 118
  • I am not sure I understand your answer. I installed specifically these 2 projects (TicTacToeLib and TicTacToeMain) from scrach, there are no other projects using them in my workspace. – ilomambo Apr 08 '13 at 19:10
  • I had the same problem with the same error (lib can't be included), in my case I was using that lib in another project, bty click on the "X" error sign and tell us the error message which will appear – William Kinaan Apr 08 '13 at 20:51
  • Do you mean the red "X" in the reference library picture I posted? Click, or double click do not bring up nothing. I can remove it and add it again, and it becomes green, but as I said, it does not stick, becoming red again next time you open that window – ilomambo Apr 09 '13 at 08:07
0

This voodoo process finally got the project to compile and run properly.
I still don't know what is it that made the difference, so if you understand, please edit this asnwer and complete the explanation.

Process:
After many unsuccsessful tries I decided to export the JAR file from TicTacToeLib project and add the exported JAR to the TicTacToeMain project. Doing that solved the ClassNotFound exception but created a new problem: duplicates resource IDs (see this post).
So I deleted the imported JAR from the libs directory and from the build path and just by a desperate act I went to TicTacToeMain propeties->Android and added TicTacToeLib as reference. I've done this before at least 4 times and it did not work. I don't know why I even tried it again.
This time I noticed at the edge of my vision that something changed in the Package Explorer pane in Eclipse. I discovered that something was added under TicTactToeMain/gen. A com.example.tictactoe.library folder containing a R.java file with renumbered ID's that do not conflict with the main project's IDs. This has never happened before in my other attemps to add a reference library. So I run the app and this time it ran OK.
As I said, at this point this is voodoo to me, I don't know what I did different now than in the previous 4 times I tried the same.

Community
  • 1
  • 1
ilomambo
  • 8,290
  • 12
  • 57
  • 106
  • 1
    Not sure if this helps, but I just loaded up the TicTacToeMain and TicTacToeLib via New Project Android->Android Sample Project. The only thing I needed to change was to go into TicTacToeMain project properties, go to Java Build Path, select Libraries and remove the 'bad' library/jar reference. After that I get a clean (well warnings only) compile. – Morrison Chang Apr 10 '13 at 06:54