My Hello World does run, but only shortly - Android - android

all I am doing:
Eclipse --> new Project --> Android Application --> Activity type: blank
no changes in the code, just the simple Hello world.
It does start, I see the Hello World on the virtual device, but then immediately shuts down.
The logcat is as follows:
08-31 06:01:14.976: W/dalvikvm(1114): threadid=1: thread exiting with uncaught exception(group=0xb2aeeba8)
08-31 06:01:14.996: E/AndroidRuntime(1114): FATAL EXCEPTION: main
08-31 06:01:14.996: E/AndroidRuntime(1114): Process: com.example.tester, PID: 1114
08-31 06:01:14.996: E/AndroidRuntime(1114): java.lang.NoClassDefFoundError: android.support.v7.appcompat.R$styleable
08-31 06:01:14.996: E/AndroidRuntime(1114): at android.support.v7.app.ActionBarActivityDelegate.onCreate(ActionBarActivityDelegate.java:107)
Any Ideas?
Edit:
Ok, apparently I for some reason have a dependency mixup:
Found 2 versions of android-support-v4.jar in the dependency list,
[2014-08-31 12:22:46 - tester] but not all the versions are identical (check is based on SHA-1 only at this
Can I simply delete one of them?

The error is essentially telling you that it can't find the Android Support Library, which it is using as a dependency.
Without knowing what build process you're using (e.g gradle) it's difficult to tell you how to fix it, but basically you'll need to either add it as a dependency, or remove the code that requires it.
For more information on the Android Support Library, try this:
https://developer.android.com/tools/support-library/index.html

If do not work the try this :
Step #1: Undo all that. If you are messing with the build path, on R16 or higher version of the ADT plugin for Eclipse, you're doing it wrong.
Step #2: Pick one of those two versions of the JAR, or pick the one from the "extras" area of your SDK installation.
Step #3: Put the right JAR in App Library.
Step #4: Delete the one from App Free, since it will pick up that JAR from App Library.

Related

Xamarin.Forms Android app is failing build with System.Security.Cryptography.Cng error

I have suddenly hit a wall with testing my Xamarin.Forms app. IT has suddenly started throwing the two messages below and failing (on my Android Emulator) immediately after the splash screen disappears.
I get the following warning during the build:
Ignoring C:\Users\geral\.nuget\packages\system.security.cryptography.cng\4.3.0\ref\netstandard1.6\System.Security.Cryptography.Cng.dll as it is a Reference Assembly
And then the Output windows shows these message when the app fails:
11-18 09:33:29.257 D/Mono (31723): Assembly Ref addref Xamarin.GooglePlayServices.Tasks[0xe1503180] -> Mono.Android[0xe15031e0]: 26
11-18 09:33:29.260 D/Mono (31723): Assembly Loader probing location: 'System.Security.Cryptography.Cng'.
11-18 09:33:29.260 F/monodroid-assembly(31723): Could not load assembly 'System.Security.Cryptography.Cng' during startup registration.
11-18 09:33:29.260 F/monodroid-assembly(31723): This might be due to an invalid debug installation.
11-18 09:33:29.260 F/monodroid-assembly(31723): A common cause is to 'adb install' the app directly instead of doing from the IDE.
In searching the web, I found a few articles that seemed related but nothing fixes the error. I have updated all NuGet packages and the Android SDK to the latest available. I am out of ideas.
https://forums.xamarin.com/discussion/63584/android-could-not-load-assembly-xxx-during-startup-registration
https://forums.xamarin.com/discussion/42405/debug-deployment-to-device-works-fine-release-fails-with-odd-messages-anybody-have-a-fix-for-this
Anyone have additional suggestions?
The actual answer was a little obvious after I had some time to come back to it. I added the NuGet package directly to my projects and now things are working correctly again. I had assumed the Reference would be sufficient, but in this case a direct reference was apparently needed. Still not sure why, or what changed that made it suddenly become a problem.
But if you get these message in the future try adding the package directly.

Is adding a libjitsi dependency to an Android project feasible?

I am actually working on an Android VOIP application that let user create conference with other users. My constraints are to avoid any use of a server like SIP servers to realise it and if I have to use a external library, it should be under LGPL license. I have succesfully done it in a peer-to-peer fashion using the AudioGroup and AudioStream classes of the android RTP stack.
My problem occurs in a 3-peers conference. Using AudioGroup, I have enabled the MODE_ECHO_SUPPRESSION but the results are very poor and I can hear my echo after 3 seconds. I came to conclusion that the Android RTP stack was not a good solution to my problem beacause using AudioGroup make impossible to tweek the sound and echo suppression seems to function badly.
By testing VOIP applications, I discovered a lot that were working pretty weel and more precisely Jitsi (homepage) which use a java library based on native code for the RTP stuff under the LGPL licence. I tried to follow this tutorial to use libjitsi but unfortunatly it gives me an error... At this time, I'm not sure that it is possible to use Libjitsi on an android project as it is normally used in Java projects.
Steps I went trough to get the error (using Android Studio)
I have compiled libjitsi from the build.xml contained in the sources and putted the resulting jar directly in the lib/ folder of my project.
I have added a dependency to libjitsi.jar in my build.gradle file
Called the static method Libjitsi.start() in the onCreate method of an activity
Error log
01-02 17:06:48.304 1523-1523/com.test.example I/LibJitsi﹕
Failed to initialize LibJitsi backend
org.jitsi.impl.libjitsi.LibJitsiOSGiImpl. (Exception stack trace
follows.) Will try an alternative.
java.lang.NoClassDefFoundError: org.osgi.framework.FrameworkUtil
at org.jitsi.impl.libjitsi.LibJitsiOSGiImpl.(LibJitsiOSGiImpl.java:34)
at java.lang.Class.newInstanceImpl(Native Method)
at java.lang.Class.newInstance(Class.java:1319)
at org.jitsi.service.libjitsi.LibJitsi.start(LibJitsi.java:227)
at org.jitsi.service.libjitsi.LibJitsi.start(LibJitsi.java:171)
at com.test.example.ui.createconf.CreateConfActivity.onCreate(CreateConfActivity.java:76)
at android.app.Activity.performCreate(Activity.java:4465)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1931)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1992)
at android.app.ActivityThread.access$600(ActivityThread.java:127)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1158)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4441)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native
Now if anyone already tried to use libjitsi on an AndroidProject or if you know it's not feasible, I would really be gratefull if you share your experience with me.
Thanks
Yes libjitsi dependency can be added to android, you can try jitsi-android which is an Android port of the Jitsi project . I have tried to run their sample app and it compiled fine.
However , I have shared 5 different libraries for VOIP calling on android in another answer you can have a look and try them.
Njoy!

fatal error: Unable to instantiate application android.app.Application

I am working on a school project to create basic android apps. It runs very well before I added few classes (I copy-paste them from my previous classes, it has the same logic/structure but different XML)
When I tried to run my 'updated' app, logCat always show this error:
05-07 09:19:15.402: E/AndroidRuntime(1370): FATAL EXCEPTION: main
05-07 09:19:15.402: E/AndroidRuntime(1370): java.lang.RuntimeException: Unable to instantiate application android.app.Application: java.lang.IllegalStateException: Unable to get package info for com.anatomi; is package not installed?
05-07 09:19:15.402: E/AndroidRuntime(1370): at android.app.LoadedApk.makeApplication(LoadedApk.java:509)
and then, on the emulator, the "unfortunately, application has stopped" message appears.
However after I pressed OK, it's not even crashing and the app runs as normal.
Am I missing something? I'm pretty sure that the .java and .xml have the right structure, and the manifest too.
This happens sometimes when pushing a new version of your app to the device or emulator, when the old version is swapped with the new version. During that time, the package is not available, and this 'crash' occurs.
This is nothing to worry about, as this scenario will not occur in 'real life' (assuming Play Store updates are handled more gracefully, as I've never seen these crashes there).

Step by Step Tic Tac Toe Android sample failure

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 imported created TicTacToeLib into Eclipse (File->New->Other->Android->Android sample project->TicTacToeLib)
Then imported created 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.
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.
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.
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.

How to add system permission file/system library to Android

I am attempting to follow Diane Hackborn's request:
For a permission that allows an application to be root, it is okay to
add the permission to the framework
<...>. However, there still must be
some kind of shared library (even if
it is a stub) for the application to
request along with it, and the package
manager should not allow the
application get this permission unless
they also request the shared library.
So I used the sdk's sample example of TicTacToe:
exported com.example.android.tictactoe.library to a /data/app/TTTLib.jar
added /system/etc/permissions/com.example.android.tictactoe.library.xml with lines:
<?xml version="1.0" encoding="utf-8"?>
<permissions>
<library name="com.example.android.tictactoe.library"
file="/data/app/TTTLib.jar" />
</permissions>
And compile com.example.android.tictactoe.MainActivity by adding a class folder pointing to the library but not adding the library itself to the .apk
It compiles, installs, starts running, but at the point when a library class were called crashes with error msg:
W/dalvikvm( 464): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
E/AndroidRuntime( 464): FATAL EXCEPTION: main
E/AndroidRuntime( 464): java.lang.NoClassDefFoundError: com.example.android.tictactoe.library.GameActivity
E/AndroidRuntime( 464): at com.example.android.tictactoe.MainActivity.startGame(MainActivity.java:51)
E/A
What do I miss? Thanks for your help.
In AndroidManifest.xml you have to enter the library dependency such as
<uses-library android:name="com.example.android.tictactoe.library"/>
Also i think you have to DEX the jar content before uploading it to the device, similar to the uploading of scala library to the device.
See http://lampwww.epfl.ch/~michelou/android/emulator-android-sdk.html and
http://lampwww.epfl.ch/~michelou/android/android-examples-in-scala/android-sdk.zip
for scripts that dexes the jar into dexed jar :)
Hope it does make any sense.
Check bin/createdexlibs in android-sdk.zip
Basically it should be something like
~/android-sdks/platform-tools/dx --dex --output=TTTLib.jar TTLLib_input.jar

Categories

Resources