How to add system permission file/system library to Android - 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

Related

My Hello World does run, but only shortly - 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.

java.lang.NoClassDefFoundError for FragmentActivity class when running Robotium

I've tried everything I could think of, but still I cannot run my tests using Robotium.
I set the robotium library and my main project to be exported in the Project configuration as suggested here
I've set the android:debuggable flag to true as suggested here
I also checked the android:targetPackage is set properly in the manifest as suggested here
Also tried to change the scope of the main project dependency when building the test module to Provided instead of Compile (I am not sure what that does...)
Here is the AndroidManifest for the Test project:
<?xml version="1.0" encoding="utf-8"?>
<!-- package name must be unique so suffix with "tests" so package loader doesn't ignore us -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.matthieu.tests"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="4"
android:targetSdkVersion="17" />
<application
android:debuggable="true">
<uses-library android:name="android.test.runner"/>
</application>
<instrumentation android:name="android.test.InstrumentationTestRunner"
android:targetPackage="com.matthieu"
android:label="Tests for com.matthieu"/>
</manifest>
And here is the exception I get:
java.lang.RuntimeException: Exception during suite construction
at android.test.suitebuilder.TestSuiteBuilder$FailedToCreateTests.testSuiteConstructionFailed(TestSuiteBuilder.java:239)
at java.lang.reflect.Method.invokeNative(Native Method)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:169)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:154)
at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:520)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1447)
Caused by: java.lang.reflect.InvocationTargetException
at com.matthieu.MainMenuActivityTest.<init>(MainMenuActivityTest.java:26)
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:446)
at android.test.suitebuilder.TestMethod.instantiateTest(TestMethod.java:87)
at android.test.suitebuilder.TestMethod.createTest(TestMethod.java:73)
at android.test.suitebuilder.TestSuiteBuilder.addTest(TestSuiteBuilder.java:263)
at android.test.suitebuilder.TestSuiteBuilder.build(TestSuiteBuilder.java:185)
at android.test.InstrumentationTestRunner.onCreate(InstrumentationTestRunner.java:373)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4218)
at android.app.ActivityThread.access$3000(ActivityThread.java:125)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2071)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4627)
at java.lang.reflect.Method.invokeNative(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NoClassDefFoundError: com.matthieu.MainMenuActivity
... 19 more
Note also that I see a few errors like this in the logcat:
01-04 14:44:51.822: WARN/dalvikvm(1263): Class resolved by unexpected DEX: Lcom/matthieu/MainMenuActivity;(0x44e7f980):0x249f70 ref [Lcom/actionbarsherlock/app/SherlockFragmentActivity;] Lcom/actionbarsherlock/app/SherlockFragmentActivity;(0x44e7f980):0x121770
01-04 14:44:51.833: WARN/dalvikvm(1263): (Lcom/matthieu/MainMenuActivity; had used a different Lcom/actionbarsherlock/app/SherlockFragmentActivity; during pre-verification)
01-04 14:44:51.851: WARN/dalvikvm(1263): Unable to resolve superclass of Lcom/matthieu/MainMenuActivity; (644)
01-04 14:44:51.851: WARN/dalvikvm(1263): Link of class 'Lcom/matthieu/MainMenuActivity;' failed
01-04 14:44:51.851: ERROR/dalvikvm(1263): Could not find class 'com.matthieu.MainMenuActivity', referenced from method com.matthieu.MainMenuActivityTest.testFirstTimeAppOpening
01-04 14:44:51.851: WARN/dalvikvm(1263): VFY: unable to resolve check-cast 849 (Lcom/matthieu/MainMenuActivity;) in Lcom/matthieu/MainMenuActivityTest;
If it makes any difference, I am using IntelliJ Idea (11.1.5), SDK 17, SDK Tools 21.0.1 and updated Robotium to 3.6
UPDATE:
Found one related discussion here. I can see different error messages whether I run only one test or all the tests, and my application does use FragmentActivity. But no matter what I do, I am not able to run any test (not one, not all)...
This type of errors occured when you did the below things.
1.If you entered wrong package name for "android:targetPackage" in manifest file.
so please check the target package name in the manifest file.
2.If you add the same library for both android app and test project.
Ambiguity occurs when you add same library for both android app and test project.so please add the library to app project only.
Finally.... I found the only way I could find to make it work there
Do not keep the Robotium test cases in a separate module... no idea why there is no way to make it work, but really I tried everything I could think of or I could find around.
I had this problem for a while and tried many things, what worked for me in the end was simply going into
properties -> Java build path -> Projects
for the test project and then removing the project under test and adding it again. (Since i cannot reproduce the problem and don't remember the details, it may be safest to remove the project under test, then clean both project, and then add the project under test)
I experienced the same problem again (see my other answer on this page) but could not solve the problem with my own solution this time. This time i found another solution: Removing the private libraries for the test project by right clicking on the test project and then
properties -> Java build path -> Libraries
and removing "Android Private Libraries"
PS My answer was inspired by information i found on this page: http://android.foxykeep.com/dev/how-to-fix-the-classdefnotfounderror-with-adt-17
I face same problem. its happen just because of i was trying to test my project with the JUnit instead of Android JUnit test.
so for that make test project right click on it > run as > Android Junit test.
it has work in my case.
best of luck

android mupdf libmupdf.so runtime error "No implementation found for native openFile"

I just finished compiling mupdf from mupdf.com on my mac. Took some time to figure it out but now I have a libmupdf.so in my libs/armeabi folder.
They provide an example of this class called MuPDFCore.java which is viewable here:
http://mupdf.com/repos/mupdf/android/src/com/artifex/mupdf/MuPDFCore.java
I used this class in my project and it says the following in LogCat:
Trying to load lib
/data/data/com.myapp.android/lib/libmupdf.so
0x4070e050
Added shared lib
/data/data/com.myapp.android/lib/libmupdf.so
0x4070e050
No JNI_OnLoad found in
/data/data/com.myapp.android/lib/libmupdf.so
0x4070e050, skipping init
No implementation found for native
Lcom/myapp/android/viewer/MuPDFCore;.openFile
(Ljava/lang/String;)I
DEBUG/AndroidRuntime(27523): Shutting
down VM
WARN/dalvikvm(27523): threadid=1:
thread exiting with uncaught exception
(group=0x400ee760)
ERROR/AndroidRuntime(27523): FATAL
EXCEPTION: main
ERROR/AndroidRuntime(27523):
java.lang.UnsatisfiedLinkError:
openFile
As far as I know the library is loading, before I figured out how to compile the library it kept crashing and saying the "mupdf" is a null link.
Their example pretty much says that openFile is a native function ... Just when I thought I figured this out another problem pops up. Ive been working on it all day. Any input would be great!
Is it a bad compile? I didn't get any errors in the terminal.
when you try to use it on your project with sample project's so files, it will throw "UnsatisfiedLinkError: Native method not found" exception. The cause is your app package name different from sample app package name("com.artifex.mupdf") because of jni binding system. You can solve this problem with below approaches:
1) long way: change mudef lib source code according to your package name, generate binaries(.so files) from it then use it in your project like #KuoCH said
2) short way: create "com.artifex.mupdf" package in your root source directory(beside project source folder, "src/main/java"), copy all classes from sample project to in it
At file mupdf.c L18-19:
#define JNI_FN(A) Java_com_artifex_mupdfdemo_ ## A
#define PACKAGENAME "com/artifex/mupdfdemo"
Change both to your package name.
I think you didn't change the your function names in mupdf.c to your corresponding java package name, that means, you should change the function Java_com_artifex_mupdf_MuPDFCore_openFile in your mupdf.c to Java_com_myapp_android_viewer_openFile.

android force close: ClassNotFoundException for Activity class

When I start my (soon-to-be) android game (from eclipse) it opens, but immediately force-closes.
Logcat says:
07-09 17:12:35.709: ERROR/AndroidRuntime(3866): Uncaught handler: thread main exiting due to uncaught exception
07-09 17:12:35.719: ERROR/AndroidRuntime(3866): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{org.anselm.eickhoff.rhythm/org.anselm.eickhoff.rhythm.RhythmGameActivity}: java.lang.ClassNotFoundException: org.anselm.eickhoff.rhythm.RhythmGameActivity in loader dalvik.system.PathClassLoader#4001e740
07-09 17:12:35.719: ERROR/AndroidRuntime(3866): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2497)
07-09 17:12:35.719: ERROR/AndroidRuntime(3866): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2621)
07-09 17:12:35.719: ERROR/AndroidRuntime(3866): at android.app.ActivityThread.access$2200(ActivityThread.java:126)
07-09 17:12:35.719: ERROR/AndroidRuntime(3866): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1932)
07-09 17:12:35.719: ERROR/AndroidRuntime(3866): at android.os.Handler.dispatchMessage(Handler.java:99)
07-09 17:12:35.719: ERROR/AndroidRuntime(3866): at android.os.Looper.loop(Looper.java:123)
07-09 17:12:35.719: ERROR/AndroidRuntime(3866): at android.app.ActivityThread.main(ActivityThread.java:4595)
07-09 17:12:35.719: ERROR/AndroidRuntime(3866): at java.lang.reflect.Method.invokeNative(Native Method)
07-09 17:12:35.719: ERROR/AndroidRuntime(3866): at java.lang.reflect.Method.invoke(Method.java:521)
07-09 17:12:35.719: ERROR/AndroidRuntime(3866): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
07-09 17:12:35.719: ERROR/AndroidRuntime(3866): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
07-09 17:12:35.719: ERROR/AndroidRuntime(3866): at dalvik.system.NativeStart.main(Native Method)
07-09 17:12:35.719: ERROR/AndroidRuntime(3866): Caused by: java.lang.ClassNotFoundException: org.anselm.eickhoff.rhythm.RhythmGameActivity in loader dalvik.system.PathClassLoader#4001e740
07-09 17:12:35.719: ERROR/AndroidRuntime(3866): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
07-09 17:12:35.719: ERROR/AndroidRuntime(3866): at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
07-09 17:12:35.719: ERROR/AndroidRuntime(3866): at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
07-09 17:12:35.719: ERROR/AndroidRuntime(3866): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
07-09 17:12:35.719: ERROR/AndroidRuntime(3866): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2489)
07-09 17:12:35.719: ERROR/AndroidRuntime(3866): ... 11 more
the interesting line here is (I think):
07-09 17:12:35.719: ERROR/AndroidRuntime(3866): Caused by: java.lang.ClassNotFoundException: org.anselm.eickhoff.rhythm.RhythmGameActivity in loader dalvik.system.PathClassLoader#4001e740
Which surprises me, because I have this class (in the right package)
edit: to clarify, added the first line which I had omitted (together with the imports)
package org.anselm.eickhoff.rhythm;
...
public class RhythmGameActivity extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
#Override
public void onPause() {
}
}
and that's all it does!
I also registered it in the manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.anselm.eickhoff.rhythm"
android:versionCode="1" android:versionName="pre-alpha">
<uses-permission android:name="android.permission.INTERNET" />
<application android:icon="#drawable/icon" android:label="#string/app_name" android:debuggable="true" android:hasCode="false">
<activity android:name=".RhythmGameActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
edit: this all has started since I renamed the activity from RhythmGame to RhythmGameActivity, but I am pretty sure I replaced all the references so maybe it is still wrongly chached somewhere? (I tried refreshing and cleaning the project)
Your help is really appreciated - im stuck!
I use Perforce with Eclipse and have discovered that Perforce's default behavior of making all files under source control read-only causes build problems that aren't clearly specified in Eclipse's build window. Also, there seems to be a quirk for me when adding a library project where even if the .classpath and .project file are writable the library may not properly associate itself with the project. I generally follow these steps for resolving errors of this nature (this assumes that the project's manifest is correct):
1) Close Eclipse. Eclipse may cache some info about a file's R/W status.
2) (Broad stroke) Make all of the files in the project writable either by checking them out from source control, or through the OS. .classpath and .project at the bare minimum should be writable.
2.5) If you placed files under source control that are generated during the build process and are a normal part of the Android build process then they should be removed from source control and made writable. Including but not limited to .class and files in the bin and gen directories.
3) Open the project in Eclipse. If there are no errors the problem may be fixed.
4) Examine the project explorer and look specifically for library project dependencies that may be missing. In my experience it's important to see all lib projects' directories and their library status icon in your project's explorer hierarchy. If a lib project folder and icon is missing, go to Properties->Android and select and add the missing lib(s). After adding a lib select "Apply" an watch the project explorer to make sure that the lib icon appears in the project directory. This step explanation may seem overly detailed, but I've been bitten several times before forcing myself to be extra observant here. If a lib won't add, try adding other dummy lib project and removing them in combination with the lib you want. No joke - this is sometimes necessary for me.
5) Clean all of the projects.
6) Read the error list and resolve any other errors.
7) Fix all of the warnings you've been putting off fixing.
8) (Not essential but important) Revert all unchanged files and observe what's left in you changelist - these are the files that will need your attention in the future to prevent build problems.
Just had the same problem. After updating ADT to the newest version, my lib folder was no longer recognized. Had to rename it to libs Now: do they really have to release new SDK every 5 minutes? Can't they create ONE stable environment for some longer time?
I had this problem once when my working application suddenly started throwing ClassNotFoundException. The problem was that the classes were not being compiled and translated to the "dex" file, this is obvious to find because the APK just shrinks.
So, in eclipse, in order to fix it just add the javabuilder to your .project file.
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
Hope it helps.
Try to fix .classpath.
Had the same problem caused by corrupt .classpath file. After fixing it the ClassNotFoundException was gone.
The background is that we are using SVN, an update caused a conflict in .classpath. Eclipse, however, did not show any error message or hint about that. I only found out when I tried to submit the current changes.
The solution here was to do a fresh SVN check out of the project, so a working version of .classpath was restored.
Not really a solution but this fixed it:
creating a new project from scratch and migrating the code
Please close this if something like it is possible here.
Thanks for all your ideas and thoughts!
Just had this same problem. Was going nuts. Fully restarted emulator/adb/and eclipse and it fixed it. Strange stuff...
Did you rename in Eclipse. Double check that it renamed with sub-package correctly. In my case it removed the dot:
Wrong: ui.MyActivity
Fix: .ui.MyActivity
I had the same problem and in my case, I had forgot to put a library in the Android Manifest. I had a MapView Activity and I had forgot to put :
<uses-library android:name="com.google.android.maps"/>.
So, you should make sure you have all your library included in your manifest.
I got this error in a FragmentActivity after updating the SDK to Android 4. The reason was, that you no longer need to include the android-support-v4.jar. Just add the support tools by clicking right mouse button on your Project, than Android Tools -> Add support library.
I know it's not your problem , but I had exactly the same problem. Suddenly my app stopped working. I didint make any change to manifest, but with some accident there was missing first row:
<?xml version="1.0" encoding="utf-8"?>
This caused ClassNotFoundException for launcher activity. I was struggling with that for few hours and I overlooked this every time I was checking manifest for possible mistake.
Strange thing happened after I have deleted this row again. Suprise, suprise app was still working. (and I didnt forget to rebuild app)
Hope this help someone to save few hours.
Perhaps your run configuration refers to the old name. Click on the little triangle next to the green run button, and select Run Configurations. Make sure the one for this project refers to the right activity name. Or just delete it and Eclipse will automatically make you a new one.

What is likely cause of Android runtime exception "No suitable Log implementation" related to logging in 3rd-party jar?

I am creating an Android app that includes a third party jar. That third party jar utilizes internal logging that is failing to initialize when I run the app, with this error: "org.apache.commons.logging.LogConfigurationException: No suitable Log implementation".
The 3rd party jar appears to be using org.apache.commons.logging and to depend on log4j, specifically log4j-1.2.14.jar. I have packaged the log4j jar into the Android app. The third party jar was packaged with a log4j.xml configuration file, which I have tried packaging into the app as an XML resource (and also as a raw resource).
The "No suitable Log implementation" error message is not very descriptive, and I have no immediate familiarity with Java logging. So I am looking for likely causes of the problem (what class or configuration resources might I be missing?) or for some debugging technique that will result in a different error message that is more explicit about the problem. I do not have access to source code for the 3rd party jar.
Here is the exception stack trace. When I run the app, I get the following exception as soon as one of the third party jar classes attempts to initialize its internal logging.
DEBUG/AndroidRuntime(15694): Shutting down VM
WARN/dalvikvm(15694): threadid=3: thread exiting with uncaught exception (group=0x4001b180)
ERROR/AndroidRuntime(15694): Uncaught handler: thread main exiting due to uncaught exception
ERROR/AndroidRuntime(15694): java.lang.ExceptionInInitializerError
ERROR/AndroidRuntime(15694): Caused by: org.apache.commons.logging.LogConfigurationException: No suitable Log implementation
ERROR/AndroidRuntime(15694): at org.apache.commons.logging.impl.LogFactoryImpl.discoverLogImplementation(LogFactoryImpl.java:842)
ERROR/AndroidRuntime(15694): at org.apache.commons.logging.impl.LogFactoryImpl.newInstance(LogFactoryImpl.java:601)
ERROR/AndroidRuntime(15694): at org.apache.commons.logging.impl.LogFactoryImpl.getInstance(LogFactoryImpl.java:333)
ERROR/AndroidRuntime(15694): at org.apache.commons.logging.impl.LogFactoryImpl.getInstance(LogFactoryImpl.java:307)
ERROR/AndroidRuntime(15694): at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:645)
ERROR/AndroidRuntime(15694): at org.apache.commons.configuration.ConfigurationFactory.<clinit>(ConfigurationFactory.java:77)
It may help to study the logic around org.apache.commons.logging.impl.LogFactoryImpl
There's probably a way of injecting a Log implementation.
http://google.com/codesearch/p?hl=en#CskViEIa27Y/src/org/apache/commons/logging/impl/LogFactoryImpl.java&l=762
http://google.com/codesearch/p?hl=en#CskViEIa27Y/src/org/apache/commons/logging/impl/LogFactoryImpl.java&l=883

Categories

Resources