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)
- I first
importedcreated TicTacToeLib into Eclipse (File->New->Other->Android->Android sample project->TicTacToeLib) - Then
importedcreated TicTacToeMain into Eclipse (File->New->Other->Android->Android sample project->TicTacToeMain) - 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:
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:
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):
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.