I'm working with an Android project I've Imported from someone else. I've got all the dependencies sorted, there are no errors in the project, but when I try and launch it, I get:
04-08 16:49:41.761: E/AndroidRuntime(19254): FATAL EXCEPTION: main
04-08 16:49:41.761: E/AndroidRuntime(19254): java.lang.RuntimeException: Unable to
instantiate activity ComponentInfo{com.me.app/com.me.app.ui.ActivityDashboard}:
java.lang.ClassNotFoundException: Didn't find class
"com.me.app.ui.ActivityDashboard"
on path: /data/app/com.me.app-1.apk
My Manifest:
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#android:style/Theme.Light.NoTitleBar">
<activity
android:name=".ui.ActivityDashboard"
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>
This seems to be a common problem, I've read all the other questions I've found and done the following, all to no avail:
ADT and the SDK are fully updated
I'm building against Android 2.3.3 (SDK 10)
This is selected under Android Build Target, and the Library is in the Java Build Path
All the classpaths in the Manifest are correct, I've double checked them all.
All Activities are in the Manifest, with the correct Intents.
and the Library is in the Java Build Path
That is incorrect. Please back out this change, then move the JAR into your project's libs/ directory.
While adding a JAR manually to your build path will satisfy the compiler at compile time, it will not add the contents of the JAR to the APK file at runtime, resulting in ClassNotFoundExceptions and the like.
Note that I am referring to third-party JARs, such as the first four entries in your screenshot. None of those appear to be in libs/, and all need to be.
The sole exceptions for the all-JARs-must-be-in-libs/ rule are:
Android's own platform JAR, attached to your project via selecting the build target (reason: this JAR's contents specifically does not need to be included in your APK)
Android library projects, which have their own libs/ directories for any third-party JARs that they reference
Your core error is that com.me.app.ui.ActivityDashboard is not found, suggesting that this is from one of your four JARs that are not in libs/.
Related
I am using ADT 23.0.2.
I just imported the google-play library to my workspace and added the reference to it in my project.
Now nowhere in my project the resource ids can be recognized because there is no R file.
(Anywhere I have R.id.blah I get the error "R cannot be resolved to a variable);
It's just gone. What am I supposed to do?
I exactly followed the steps by developers.google.com. It's nothing complicated but I don't know why this happened.
(I have all layout files in place and no import for android.R are in my class files.)
Before adding the
Tools I use:
Here are screenshots from my app properties:
My manifest
<permission
android:name="com.appname.appname4.MAPS_RECEIVE"
android:protectionLevel="signature">
</permission>
<uses-permission android:name="com.appname.appname4.MAPS_RECEIVE"/>
<activity
android:name="com.appname.appname4.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.appname.appname4.SearchResultListActivity"
android:label="#string/title_activity_search_result_list"
android:parentActivityName="com.appname.appname4.MainActivity" >
<!-- Parent activity meta-data to support 4.0 and lower -->
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.appname.appname4.MainActivity" />
</activity>
<activity
android:name="com.appname.appname4.ContactInfoActivity"
android:label="#string/title_activity_property_detail"
android:parentActivityName="com.appname.appname4.SearchResultListActivity"
>
</manifest>
I had similar issues when I first started Android programming. Here are some fixes that worked for me in the past.
1. Fix/Check all xml(layout) files.
Many times a R file not being generated is due to an issue with your layout file or Android Manifest file. Follow this link and work your way down the page checking permissions and the general layout format.
2. Project/Clean.
go to Project->Clean.
Also make sure you have selected the option to build project automatically.(Without this option check marked R file is never generated automatically).
3. Fix Project Properties.
Right click on your project in Package explorer then choose fix project properties.
Repeat Step 1 after this.
4. Builders.
Go to Project->Properties then Builders. Select the appropriate boxes.
Repeat Step 1, and Clean and rebuild project.
5. Appcom7 and Google Play services error.
Sometimes to fix errors associated with installing these two reference libraries. I copy there folders into a generic library folder on my hard(where I keep most of my eclipse reference libraries), after this I delete them from the Package explorer and from the "default" directory where they were installed. I Fix project properties again and clean/rebuild. This should get you back to your non-reference library version of the package. Then I manually add them as Projects to my eclipse IDE and finally follow this to add them as references to my project. Then fix project properties,clean and rebuild.
6. Reference Question.
Finally, referring to this StackOverflow page has helped me countless times. And one way or another fixed my issue.
Good Luck.
I am trying to create an application that has different flavours (e.g. free, paid), by putting as much common code as I can into a library, and making projects for each flavour. At the moment, the Java class for the main activity will be the same in all versions, it is merely the layout and some constants defined in the "values" resource directory that need to change to control the behaviour.
I have defined the activity in my "free" project's manifest file as follows:
<activity
android:name="librarypackagename.Foo"
android:label="#string/bar"
android:launchMode="singleTask"
android:uiOptions="splitActionBarWhenNarrow"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
But when testing the application, I receive the following error:
"Unable to instantiate Activity ComponentInfo{freeapppackagename/librarypackagename.Foo}: java.lang.ClassNotFoundException: Didn't find class "librarypackagename.Foo" on path: DexPathList[[zip file "/data/app/freeapppackagename-2.apk"],nativeLibraryDirectories=[/data/app-lib/freeapppackagename-2, /vendor/lib, /system/lib]]"
Is it not possible to use an activity from a library as the main activity? I have also tried this by extending Foo in my free app project, and using that as the main activity, but I still get the same exception.
Edit (removed manifest files, as it turned out they weren't related to the issue):
Also, in Eclipse, I've just noticed I am getting the following error message (although the project still builds):
Found 2 versions of android-support-v4.jar in the dependency list,
but not all the versions are identical (check is based on SHA-1 only at this time).
All versions of the libraries must be the same at this time.
Versions found are:
Path: D:\Work\Eclipse\LiteApplicationName\libs\android-support-v4.jar
Length: 556198
SHA-1: 4a6be13368bb64c5a0b0460632d228a1a915f58f
Path: D:\Work\Eclipse\LibraryName\libs\android-support-v4.jar
Length: 385685
SHA-1: 48c94ae70fa65718b382098237806a5909bb096e
Jar mismatch! Fix your dependencies
Strangely enough, the android-support-v4.jar file appears in "Referenced Libraries" in the application project, but in "Android Private Libraries" in the library.
There are a couple things to look out for.
Where you define your activity's class, ensure you have something to the effect of package com.librarypackagename; at the top of the file.
You should have two AndroidManifest.xml files, one for your library and one for your main project.
In your library AndroidManifest.xml, ensure that the element defining your activity has a parent XML tag that is <library> and not <application>
In your library AndroidManifest.xml, ensure that you are setting the package attribute to something like com.librarypackagename
Let me know if you have any questions about any of these points. It would be helpful if you provided more information about the current structure of your project.
Turns out that it was related to the library mismatch issue. I right clicked on the application project, and selected Android Tools > Add Support Library. This installed a package, and then "android-support-v4.jar" appeared in the application project's "Android Private Libraries" directory as well. Now I am no longer getting the exception.
I just used Android SDK Manager to update Android SDK Tools to revision 17, and Android Compatiblity to revision 7. Now, the program I've been running for ages crashes on startup.
Narrowing down the issue, I have created a new blank project, added android-support-v4.jar to the build path, and changed Activity to FragmentActivity and that's all. Now it crashes.
The error message is:
java.lang.ClassNotFoundException: com.example.test.TestActivity in loader dalvik.system.PathClassLoader[/data/app/com.example.test-2.apk]
The code is:
package com.example.test;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
public class TestActivity extends FragmentActivity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
Everything else, including the manifest, is unchanged from the defaults. Any help is much appreciated!
Edit: Manifest included below:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.test"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="9" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name=".TestActivity"
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>
</manifest>
Turns out it's a problem with Android SDK Tools r17. I had previously been using the method given in the tutorial at:
http://mobile.tutsplus.com/tutorials/android/android-compatibility-working-with-fragments/
However, this no longer works. Instead, all I needed to do was right-click on my project in Eclipse and choose Android Tools-->Add Support Library...
Doing this means it is no longer necessary to go to Java Build Path and click "Add External JARs..."
Many thanks to eMich for this solution from: Jar-file issue with ADT r17
I had the same issue and none of the answers I found in stackoverflow solved my problem. After hours of several (many) trial-and-error, I solved my problem by configuring build path of my project. In Eclipse, right click the project > Build Path > Configure Build Path..., in Order and Export tab, check Android Private Libraries, click OK. After that, clean up the project and try running again.
I solved this problem by comparing my project with other (newly created) project that could run as expected. I compared each configurations and AndroidManifest.xml of them.
Hope this helps you too :)
UPDATE Other solution: using ANT
I found another way to solve this problem: using ANT. My friend faced the same issue, but fixing the build path didn't solve his problem. I don't know whether it was because we use the different IDE version, different ADT version, or different operating system (I use GNU/Linux). And then, I suggested him to use ANT rather than the IDE's one.
First, setup the project (create build.xml) by executing android update project -p <project-dir> -n <project-name> for each project (including library projects). And then, from the main project's directory, execute ant debug to build, ant installd to install, and run the application.
The strange thing was, once he succeeded with this way, he even can compile by using IDE again, without ANT at all.
I assume that fragment activity is listed in the manifest properly? Here's my main FragmentActivity class in the Manifest:
<activity android:name=".Polling" android:label="#string/app_name"
android:windowSoftInputMode="stateHidden">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
select your project in Package Explorer > Right Click it > Android Tools > Fix PRoject Properties
and also
Try Project > Clean
Then rerun.
I got the
java.lang.NoClassDefFoundError: com.android.example.SupportFragment
at com.android.example.SupportFragmentActivity.onCreate()
on PopupMenu
SupportFragment extends SherlockFragment implements PopupMenu.OnMenuItemClickListener
...
#Override
public boolean onMenuItemClick(android.view.MenuItem item) {
return onOptionsItemSelected(item);
}
when trying to make a api 17 app compatible with api 8, the only indication was the logcat error above, so check that all your imported classes are supported if you get this error.
Same issue got solved by Doing Build path->Configure Build path->order and export->Check Add private libraries->ok.
Then clean up the project.
Done a big problem solved.
I also got the same issue, and resolved it by the below way.
If because of some reason you have UNCHECKED to the private libraries from build path, so just add Androidv-4 jar in build path and enable(check) it in "Order and Export" tab
Remove anything lib about v7 or v4. Move your Android project, Alt+Enter, click android, look is lib: make sure there is nothing about v7 or v4 lib
add v4 lib
clean project
run again
if you remove v7, will be error with styles... you may look this
I have an android project that I want to "clone" for a second similar project which only differs by one file: it's sqlite database (assets/mydata.sql).
I've turned the source project (reslib) into a library and added it to my clone project's properties (the source project shows up under "Library Projects" as reslib.jar)
Thing is, I'm not sure how to launch the main activity in the source project. The source project's main activity sets-up a TabHost. How do I launch into the source project's main activity from my clone project? I started pasting code into "cloneActivity.java" to fire up the TabHost but then wondered if there was a better way.
Doing this is pretty straight-forward. In the manifest for your dependent project, you need to specify the source project's activity as the one you want to launch.
Suppose your source project has package name com.example.source, your dependent project has package name com.example.dependent, and the main activity in your source project is MainActivity.java.
Then in AndroidManifest.xml in your dependent project, you would have something like the following:
<application
android:icon="#drawable/logo" >
<activity
android:name="com.example.source.MainActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- possibly lots more activities and other declarations -->
</application>
Important Notes: In the manifests for both your source project and the dependent project, you must make sure to list all activities, permissions, etc. If later on you add an activity to your source project, you'll need to remember to add it to the dependent project's manifest as well.
Also, you'll need to copy anything in the source project's assets directory to the dependent project—and don't forget to keep that in sync as well. (This is true as of June 2012, I've heard that some future version of the Android build tools will likely alleviate this headache.)
And finally, if you use Eclipse to create the projects, it will create a default layout main.xml. Since resources in the dependent project override resources in the source project, make sure this doesn't trip you up.
Okay I have a project that is using the android-rss library (org.mcsoxford.rss). I created a separate library project for the android-rss. When I try to run my project I get an error saying that the launch was canceled. "Installation error: INSTALL_FAILED_MISSING_SHARED_LIBRARY". I went through the tutorial on Android on how to reference the library eclipse project. I have everything setup right. I also put in the xml file a uses-library. Not sure what the problem is. Here is my the uses in the Android-Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
...
<uses-library android:required="true" android:name="org.mcsoxford.rss"></uses-library>
...
</manifest>
And I have it referenced in the ANdroid Library. I can build the project and see the reference to the library in the project. No errors nothing. The reference lib is exported too.
Here are my console output errors:
[2011-04-18 11:46:43 - BOTM] Installation error: INSTALL_FAILED_MISSING_SHARED_LIBRARY [2011-04-18 11:46:43 - BOTM] Please check logcat output for more details.
[2011-04-18 11:46:44 - BOTM] Launch canceled!
I haven't check that yet, but maybe it will help.
Please download android-rss from: https://github.com/ahorn/android-rss and look into README file.
That part may be useful:
"To reference this library project from within your Android application,
navigate to the /tools/ directory and use the following command:
android update project \
--target \
--path path/to/your/project \
--library path/to/android-rss
This command appends to the "default.properties" file in your Android
project a new "android.library.reference" property. The value of this
new property should be the relative path to the directory which you
created when you fetched the Android RSS library source code with Git.
The library is compiled by the Android build framework when you build
your mobile app which was specified in the --path argument above."
Did you mention in the application launcher activity in the manifest file as follows,
<application>
<activity android:name=".LoginScreen"
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>
Here Login screen is my main activity to launch as soon as app starts.
While installing the application on to the device, PackageManager checks for the shared libraries that are been used by the application.
If the shared libraries are missing on the target device, it will not allow user to install the application on that device.
So, basically the library "org.mcsoxford.rss" is missing from the device on which you are trying to install your application.
In order to over come this installation issue, you can make the following change on the manifest file:
android:required="**false**"
The above field states that you application will still work with out the library that has been mentioned on the uses-library tag. This will allow the application to be installed on the device, even if the shared library is missing.