I recently published an app to the market and I'm now getting an error by some user, the app presumably crashes right when it starts. Unfortunately I can't contact him directly and the app works fine in the emulator as well as on my phone (and some friends' phones).EDIT: I guess that this happens to more than one user as I received comments in the market like "crashes on start" or "doesn't work". I only received this one stacktrace but there's no info about the configuration, device, Android version, etc.
The app is a simple soundboard, so there's really no magic involved, but I can't get why it fails on some phones. Here's the stack trace I'm getting, I hope anybody can help me out:
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.my.app/com.my.app.SoundMachine}: java.lang.ClassNotFoundException: com.my.app.SoundMachine in loader dalvik.system.PathClassLoader[/mnt/asec/com.my.app-1/pkg.apk]
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2585)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
at android.app.ActivityThread.access$2300(ActivityThread.java:125)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
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 java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:876)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:634)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: com.my.app.SoundMachine in loader dalvik.system.PathClassLoader[/mnt/asec/com.my.app-1/pkg.apk]
at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577)
... 11 more
These are the first couple of lines from my activity:
public class SoundMachine extends Activity {
private SoundManager mSoundManager;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
EDIT: This is the (almost) complete onCreate:
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mSoundManager = new SoundManager();
mSoundManager.initSounds(getBaseContext());
int counter = 0;
for (Integer soundFile : soundFiles) {
counter++;
mSoundManager.addSound(counter, soundFile);
}
ImageButton SoundButton1 = (ImageButton) findViewById(R.id.sound1);
SoundButton1.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
mSoundManager.playSound(1);
}
});
SoundButton1.setOnLongClickListener(new OnLongClickListener() {
public boolean onLongClick(View v) {
saveSoundChoice(soundFiles[0], soundNames[0]);
return true;
}
});
(...more of this...)
Button StopButton = (Button) findViewById(R.id.stopbutton);
StopButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
mSoundManager.stopAll();
}
});
}
And here's my manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.my.app" android:installLocation="preferExternal"
android:versionCode="9" android:versionName="1.2">
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:name=".SoundMachine" android:label="#string/app_name"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-sdk android:minSdkVersion="3" android:targetSdkVersion="8" />
</manifest>
So all possible errors I already read about here and in some forums don't apply to my app.
The activity is present in the manifest.
The super-method is called in the overriden method.
The ContentView is set before accessing elements in the view.
I know it's hard to pinpoint the source of an error without being able to reproduce it, but maybe somebody has a bright idea and can help me out.
Some questions:
Do I need the "intent"-part in the manifest? Eclipse created it when I created the project. (Yes, according to Mayra)
Should the super-method be called where it is? (Yes, according to Mayra)
EDIT: The main question that remains now is: How come the path in PathClassLoader is different from my package-name? The page John J Smith posted seems to deal with the same problem, but I don't understand the fix that was applied there.
Thanks, Select0r
I solved this problems by selecting :
Project->properties->order and export
select the all external jar files.
clean and build it solved the issue
Since ADT update to revision 22 (May 2013) you have to check "Android Private Libraries" check box in Project -> Properties -> Java Build Path -> Order and Export in Eclipse for your older projects to get rid of this exception ...
I just got the same error (Unable to instantiate activity...) with Opera Mini. Opera Mini was on SD card (moved to SD card in the app setting). The error seems to be related to the fact that I swapped the SD card yesterday. The device was shutdown, I copied all data from the old card over to the new card (with cp -a) and then inserted the new card and started the device again. Everything seems to work as expected, but I see now that all apps on the SD card crashes with the same error.
Device: HTC Desire HD (Android 2.2)
Old SDHC card: SanDisk 8GB class 4
New SDHC card: Kingston 16GB class 4
So I would say that this is a an Android bug and not something that can be fixed by app developers.
Also see:
http://android-developers.blogspot.com/2010/07/apps-on-sd-card-details.html
It has always been the case that when you swap SD cards on an Android device, if you physically copy the contents of the old card to the new one, the system will use the data on the new card as if nothing had changed. This is also true of apps which have been installed on the SD card."
This seems to be incorrect.
This happened to me when I refactored one of my package names and the refactor tool removed the leading "." from all of my activity names. so in the AndroidManifest.xml, I had to change android:name="MyActivity" to android:name=".MyActivity"
hope this helps someone, I just wasted a bunch of time o
This doesn't apply to the OP's question, but it did to mine and it took me quite some time to figure it out: when using the Google Maps API, make sure you've included the library declaration in the application manifest.
For instance:
public class MyActivity extends MapActivity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
#Override
protected boolean isRouteDisplayed() {
return false;
}
}
In AndroidManifest.xml:
<application>
<uses-library android:name="com.google.android.maps" />
<activity android:name="MyActivity" android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
I don't know why the path in the PathClassLoader is different to your package name but when testing on the emulator try forcing a close then run it again, as per this link
I had the same problem of you and, after hours of search, I discovered something interesting. I'll try to expose that as clearly as possible:
I created a project with a package called "myapp.sound" containing the activity. Program ran normally;
I renamed that package calling it "app.soundapp" and program still ran normally.
However, in the manifest.xml file of the program there was something strange: the name of package was the old "myapp.sound". I changed manifest with correct new name and, from that moment on, our error occured. I don't know why, but seems that the "package name changer" of Eclipse doesn't update all the dependencies. If it's not strictly necessary, don't rename the package containing activity.
Maybe, to solve your problem you have to create a new project and copy inside it all your java class.
Look at the package defined at the top of the manifiest file and make sure that it matches the package where you class is defined.
My problem was that I did not have matching package names.
Also enusre that you have a folder named "libs" with an 's'. Put all of you jar files that you added inside it and add to build path.
This problem can also occur if you have a constructor with one or more parameters in your activity class.
This problem might exist when you change the name of your class and update the manifest file and the manifest file is not updated on the emulator. Try uninstall the application from emulator and then reinstall it. This will work.
I was coming across this problem when I was including java Projects in my buildpath for my android project targeting JavaSE-1.7.
For some reason my emulator would not throw a class not found if the java project it was including was originally created targeting JavaSE-1.6. Eclipse would give me a warning "Build path specifies execution environment JavaSE-1.6. There are no JREs installed in the workspace that are strictly compatible with this environment." But the Android emulator would launch and I would not get a classnotfoundexception
So if you are including projects that target JavaSE-1.7, remake them targeting JavaSE-1.6 and this may solve your problem.
Good luck!
Similar to Bobf Cali, I first saw this error after renaming my base package to change the "example" section. To fix it, I had to delete my gen and bin directories, clean the project, and rebuild.
Note depending on what version of the eclipse android plugin you're using (if any), you may also have to update activity names in your AndroidManifest.xml
Saw the same error message after doing a simple upgrade of my app. Fixed it by doing this:
Project->Build automatically OFF
Project->Clean->Selcting my project
Then I did a new export of my signed app, and it worked.
Are you sure your package name is unique? I don't know what happen if the user has another app using the same package name, but maybe it can cause strange errors like this.
EDIT: I just saw this page, it remembers me I already had this problem when downloading an app from the Android market. The app crashed on startup, I tried a lot of times but I always ended with the same result. Then I tried to uninstall the app, reinstall it, and everything worked fine. I'm still using it today and the problem never happened again.
On my link, you can also see that they reproduced your error by making the app unreachable (unmount SD), so it's definitely not a problem with your code.
Check out this article: http://www.androidguys.com/2010/05/22/storing-apps-sd-froyo/ which explains the limitations of storing apps on SD cards. If your users have their SD card mounted by a computer, that might make the SoundMachine class invisible. And I wonder if the cp command fails (perja's attempt to fix) because it might change the ownership of the files such that the userid of the app and the ownership of the files don't match anymore.
I had the same issue in a recent Android project. The problem turned out to be pretty simple yet it was hard to locate. This happened to me then I refactored the package name of the entry point activity of the app. This created a conflict with the gen/.../R.java file, since the package there was not refactored. Eclipse did not complain, but at runtime i got the same error you posted: could not instantiate... classNotFoundException...
Lesson learned from this: do NOT refactor the package name that holds your main activity!
Hope this helps you or anyone breaking his/her head over this error!
I solved this and could locate the causes:
-The Manifest will be corrupt. Even if the package-structure is right and every single data was written down correctly the activity will not be found.
-R will be in the package-structure which was first declared before renaming.
-The run-configurations are setup with the wrong package of R. So the activity can't be found.
What we have tried:
-Manually editing the run-configs via export/import
-Manually renaming the package-structure
-Manually renaming the R-package-structure
-Deleting the run-config (it will be rebuild if you try to start the app)
Solution:
Try to setup a new project without reusing your manifest. I have tried to reuse it and got the same problems all over again. So after the main cause has to be the corrupt manifest.
I hope this helps!
Make sure your /src dir is listed in your projects>properties>java build path>source
Maybe it is too late to solve your problem but hopefully it will help someone else.
I had a similar problem and after many tries, I decided to delete R.java. That did the trick.
This error can also occur when you (at the project level) incorrectly Import > Android > Existing Android Code Into Workspace, via Eclipse. In my case, this resulted in an empty "src" folder, but then I noticed new folder starting with "java" at the root and continuing with the package path (i.e. com/zyzcorp/...), leading to the MainActivity.java file.
To test what I thought may fix the problem, I copied the com.*.MainActivity.java file into the src folder, refreshed, cleaned, and restarted Eclipse. I was able to build and run the app on the target device.
I don't see anything obviously wrong. All I can say is to try to test it in as many different configurations as possible.
Test it in the emulator for every possible SDK level, follow the guidelines for testing on different sized screens (although that doesn't seem to be your problem).
Try to test it on a phone from each of the major providers, if you can find friends that have them: HTC Sense, Motoblur, etc.
If you only get one report, it might just be something screwy with that guys device. See if you get other, similar reports that add more data.
You had renamed the package anytime? This normally happens if the package was renamed after creation. Following link should be helpfull in that case http://code.google.com/p/android/issues/detail?id=2824. If this is not the case,please post your complete manifest file.
I has the same problem but this fixed it. In my androidmanifest.xml i had this line called android:name = myappnameActivity. Although my class name was just myappname. Hence i took off the Activity part in the xml file and all was fine.
I was just having a problem with this myself, so I want to bring up what caused the problem for me. I had just included some new libraries setting up expansion APKs. The libraries are dependant on each other and I was only including one of them in my properties > android > libraries.
So this could happen if the user is missing a library on their phone that most users have.
It showed ClassNotFoundException on my main activity because it implements a class which was in the missing library.
I had 5 different packages. And for some reason the compiler was looking for the activity on the wrong package.
So I switched my activity and all the class that inherits the activity to the package that it was looking into.
I got the name of the package it was looking for in the beginning of the logcat.
I fix this problem by deleting "bin" and "gen" folder, and rebuilding project.
I had the same problem
I solved it by
uncheck the Android Dependencies from Project--> Properties-->Java builder Path-->android dependencies
Delete BIN and GEN folder files. Rebuild, everything should work. Check if theres another error below the "unable to instantiate", sometimes another error is firing this (activity cant load because of something even if its class has been found.
What I had to do is just re-do the building/exporting process with no modification to the code whatsoever. It worked for me, which I did was to export it two times. On my first export, the build APK has lower file size and the second export (with no any modification to the code/configuration) produced a slightly larger file size (about 200KB diff).
This bug in building is really costly, kills you in front of your manager, and should be really fixed by Android/Eclipse team. Kind of sucks
After spending 6 hours on this issue, found that it was a silly mistake. Apparently if you're defining your Application class in android manifest and you have enabled MultiDex enabled, you have to add that on Application Class. Here is example from my app.
It only gave me error on devices running on < Android 5.0
AndroidManifest.xml
......
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme"
android:name=".AppClass"
.........
AppClass.java
class AppClass : Application() {
override fun onCreate() {
super.onCreate()
}
override fun attachBaseContext(base: Context) {
super.attachBaseContext(base)
MultiDex.install(this) //Don't forget this !!!!
}
}
Related
I am new to programming generally please I need some help!
My app was installing successfully after every update until i decided to add the 'com.github.PhilJay:MPAndroidChart:v3.1.0-alpha' library to the app because i need the user to be able to view some data in form of statistical charts.
The library was synced successfully and have used packages and classes therein successful. But when i try to install the app in my android device it returned this error:
Installation failed with message Failed to commit install session 590492354 with command cmd package
install-commit 590492354. Error: INSTALL_FAILED_MISSING_SHARED_LIBRARY: Package couldn't be installed in
/data/app/com.cenitscitech.www.etimebook-jOP-jv2YuNu7_8qnkfqp-A==: Package com.cenitscitech.www.etimebook requires unavailable shared library com.google.android.things; failing!.
It is possible that this issue is resolved by uninstalling an existing version of the apk if it is present, and then re-installing." I have pasted a screenshot here:
I uninstalled the existing version of the apk, cleared some memory space but keep on getting the same message! What should I do next please?
You are most likely installing on a device that is not an Android Things device. I suspect the library you added either has some transitive dependency on com.google.android.things, or something else changed in your project.
To get around this, you must do the following 2 things:
1. Mark that Android Things is not required on the device in your AndroidManifest.xml file:
<uses-library
android:name="com.google.android.things"
android:required="false"
tools:replace="android:required" />
(tools:replace is not strictly required, but it just there in case something in the manifest merge process overrides your setting.)
2. In your app's code, before making any calls to the Things APIs, make sure that they are available on the current device. This can be tested with the following code snippet:
public boolean isThingsDevice(Context context) {
final PackageManager pm = context.getPackageManager();
return pm.hasSystemFeature(PackageManager.FEATURE_EMBEDDED);
}
Only doing 1 should fix the install problem, but your app will crash if you make any Things API calls on a device that isn't an Android Things device.
Had a look in the com.github.PhilJay:MPAndroidChart:v3.1.0-alpha repository and did not find any reference to com.google.android.things inside the source code.
You need to remove the below entry in case it's found in the AndroidManifest.xml of your app for it to work on your device again:
<uses-library android:name="com.google.android.things" />
I have a react native application and I changed the package name of the application using https://www.npmjs.com/package/react-native-rename. After that I tried to run the project but its saying that the application is not registered. I have tried the following steps also.
Opened the project in android studio and make sure that the package name is changed and all the files are also in the same package name.
Tried cleaning the old gradle files.
Uninstalled the previously installed version of the app (The one which have the original package name.
Any help would be appreciated. Thanks in advance
You need to check 2 files to make sure you have equal names there:
index.js -> application name in the last line:
AppRegistry.registerComponent('YourAppName', () => App);
app.json -> name property
In both places names should be equal (case sensitive).
Have you changed the values in the index.ios.js, index.android.js and app.json files?
There are some instructions here.
android\app\src\main\java\com{someFolderName}\MainActivity.java
you landed up on this answer because still you are not able to solve the issue
open the file mentioned in above in title
this used for
Returns the name of the main component registered from JavaScript.
This is used to schedule rendering of the component.
look for method
#Override
protected String getMainComponentName() {
return "AddYourNewNameHere";
}
which might be returning a hard coded string replace it to desired name!!
EXTENDED TIP
ensure you clean your gradle demon as the project does not compile sometimes
for that use following
cd android
gradlew clean
I have gone through every possible adjustment variable I could find to try to try to make this work:
I adjusted sdk versions: android:minSdkVersion="19" android:targetSdkVersion="22"
I made sure that all my settings matched this: https://library.vuforia.com/articles/Solution/Integrating-Cardboard-to-the-ARVR-Sample
I also followed these instructions for Android:
https://developer.vuforia.com/forum/faq/unity-player-settings
I even changed AndroidManifest.xml to be AndroidManifest-Vuforia.xml
I'm running
Unity 5.3.0 / Vuforia6.0.117 / Samsung Galaxy S6 Active / And the latest google cardboard
The program compiles and runs perfectly on my webcam, but the second I install it on my phone and run it, I keep getting the same Vuforia Initialization Error no matter what I do. And yes, I made sure to give the app permission to use the camera.
Can anyone help? I've scowered the internet and I cant get the thing to work.
Under the 'Vuforia' menu, click 'Configuration', then disable the 'webcam' setting.
I had this problem and it was because I didn't write my Vuforia license key. In the class SampleApplicationSession find the line thats similar to this:
Vuforia.setInitParameters(session.mActivityRef.get(), session.mVuforiaFlags, "KEY_HERE");
It could be on line 370 or 414. But insert your key there and that could fix it.
I had same problem in android studio to fix it I first get licenseKey from here and then go to Project-> app/cpp/Croossplatform/AppController of my projects and then go to the
namespace
{
constexpr char licenseKey[] = "your key ";
}
line 55-60 AppController
This seems to be a problem in the Vuforia Unity package. Download the latest Vuforia-Unity package from https://developer.vuforia.com/downloads/sdk and import the new package into the project and replace the old package. This should resolve the error.
Other possible fixes that didn't seem to help in my case included: giving camera permissions in AndroidMainfest File, changing the Vuforia API key and disabling Vuforia Play Mode.
Trying to make an app using phonegap 1.4.1 + phonegap's childbrowser plugin.
I've been following guides and digging a lot on the subject, but I'm stuck on an error I can't understand.
I've moved the childbrowser.java to the correct location and added this to the plugins.xml:
<plugin name="ChildBrowser" value="com.phonegap.plugins.childBrowser.ChildBrowser"/>
added this to the androidmanifest.xml:
<activity android:name="com.phonegap.DroidGap" android:label="#string/app_name">
<intent-filter>
</intent-filter>
</activity>
But I get an error on the ChildBrowser.java on this line:
package com.phonegap.plugins.childBrowser;
telling me that the declared package com.phonegap.plugins.childBrowser does not match the expected package com.phonegap.plugins.ChildBrowser.
I changed it to capital C in childbrowser.java, and the error went away, but ofc, the plugin didn't work.
i found this topic, discussing it, but no appearant fix
http://comments.gmane.org/gmane.comp.handhelds.phonegap/11993
I have tried renaming the plugin name in plugins.xml
Earlier, i was trying to whitelist some url's, but kept getting them blocked, so i'm thinking there's something wrong with my /res/xml directory? its meant to be projectroot/res/xml, right?
Any help will be greatly appreciated.
If you've created the package "com.phonegap.plugins.ChildBrowser" in your Eclipse project then you need to modify the plugins.xml line to be:
<plugin name="ChildBrowser" value="com.phonegap.plugins.ChildBrowser.ChildBrowser"/>
to match the actual package of the plugin.
Make sure the ChildBrowser java file is in the package you declared in plugins.xml, which is in root/res/xml/ folder.
You need to add the javascript file to your main page, so the page can call it's methods. Check that the javascript file contents are consistent with you java file location - for example the packages may be different.
Add the right permissions
Make sure you call the plugin from javascript the right way, for example in phonegap 1.3 it goes like this:
window.plugins.childBrowser.onLocationChange = function(loc)
{
...
i'm trying to get android running on a gumstix overo system.
since i'm not planning to use the final "product" as a phone, i asked my self if it is possible to exclude applications like the phone/dialer-app from the kernel build-process (any config parameter probably?)
Just remove (or comment) these lines:
<project path="packages/apps/Phone" name="platform/packages/apps/Phone" />
<project path="packages/apps/VoiceDialer" name="platform/packages/apps/VoiceDialer" />
(and others if needed) from the platform manifest (default.xml) :
https://android.googlesource.com/platform/manifest/+/master/default.xml
Removing the app declarations in the repo manifest did not work for me, as there are other libraries that reference them that then fail to compile. The build system approach to this problem is to create/modify your product definition makefile to not include the specific apps.
So, for the overo you probably already have a products/overo.mk product file. You can manually set the PRODUCT_PACKAGES variable to which applications you want to ship. You will also want to take a look at the PRODUCT_POLICY variable, as it defines sets of applications for your product type.
It can take some fiddling to get everything to build correctly, due to interdependencies between applications, but the Android build output does a pretty good job of explaining the problems when they arise.