Renamed packages and now activity cannot be found - android

So today I had a bright idea to rename my packages, now my android application which I have schedule for release on thursday is not working.
I am getting a similar error as follows:
Error: Activity class {org.me.androidapplication2/com.albertrosa.DEMO.MainActivity} does not exist.
I have modified the manifest to reflect the change:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.albertrosa.DEMO"
android:versionCode="1"
android:versionName="1.0"
there is more to the manifest but this is all that I have changed. is there something I am missing or doing wrong. I am using netbeans to build this app.

This is an old topic but someone may find it useful to know when you refactor your package you are required to edit the manifest file but you also need to refactor the generated java files package.

As you can see, there is a wrong package path here: org.me.androidapplication2/com.albertrosa.DEMO.MainActivity
Have you tried to clean the project? Rebuild? Try to search for the old package name, maybe it is hard coded somewhere?!

Exactly this just happened to me. Uninstalling the application from the device fixed the problem.

Related

Eclipses does not seem to generate the correct Blank Activity android project

Hey guys I am new to Android development with eclipse. I am following the walkthrough on the google website (here) and already hit an issue with it. I've installed the SDK and eclipse as instructed. Now I am trying to create and run a default Blank Activity android app. When I create the project, eclipse creates an appcompat_v7 project along side my MyFirstApp project. When I hit run, the app seems to be build without any issues and the log tells mw that it is installed on my app. But nothing happens, and I can't find it on the device.
Now the reason I think that it is not getting generated is because that Android Manifest is very barebones and missing lots of vital things by the looks of it:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myfirstapp"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
</application>
Secondly, the next step in the tutorial asks me to open up the fragment_main.xml file from the res/layout/ directory. This file does not exist. The directory is empty, there is nothing there.
I don't get any errors so I am not sure what has gone wrong.
So after a long discussion with #Prodigga, we came to the point where we think it is better to take a step back and wait for things to settle with the new SDK release (api level 21).
By the way, tutorial in the question is not outdated. There is this minor problem with the new sdk.
I don't know what is causing the problem and I don't know the solution yet but there is a workaround. If you only want to create a blank activity, given that you are experiencing the same issue, do as follows
Uncheck "create activity" check box when configuring your new project.
Create the package and MainActivity manually.
Add it to the manifest manually.
If you would like to benefit from code auto-generation, then I recommend downgrading the sdk. For example, you could use this ADT bundle (10/30/2013 - Windows 64-bit), but don't try updating the SDK to level 21, not yet.
In your android manifest file, add an activity element as the child of the application element. Add the name of the Activity class that you would want to show on the launch screen. See the below link on the syntax for this:
http://www.mkyong.com/android/how-to-set-default-activity-for-android-application/

IntelliJ IDEA - Can't build anything, always get "package R does not exist"

I'm trying to use IntelliJ IDEA to work on an Android app with a colleague that swears by it, but I'm unable to build any of the Android projects he sends me because whenever I try a build I get an error saying package R does not exist.
I have been trying out everything I can think of. Examples and other things to note are:
Making sure I have a version of the local.properties file pointing to the root of my Android SDKs folder.
Fiddling with various settings in the project structure dialog (I won't list them all).
The project I'm working on has two library projects with also use the R class and they work fine.
The intellisense within the IDE recognises the R class and comes up with the stuff I expect.
Any help would be greatly appreciated. I feel I'm missing something basic.
I am brand new to IntelliJ so I apologize if this doesn't work for you. I was experiencing the same problem and the solution was to add an Android Facet to your project.
(I am on a Mac, so directions here may be slightly off, and there are probably better ways to find this window, if so let me know!)
Right click your project and go down to Open Module Settings (seems F4 also works)
Select Facets in the far left column
Click the + button
Add an Android Facet to your project, and VOILA!
You may need to import your Rs now, which could be a huge pain... so hopefully someone can chime in with an easy way to auto-import
Hope this helps someone!
Another possible solution to those listed here is to check that the package name in your AndroidManifest.xml matches that of your actual package:
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.yourpackagename" >
My package was building fine until I refactored the package name, everything refactored except for the package name in manifest file (see above) which caused the error "Package R does not exist".
If you run into this with a package that has been building before you need to "Rebuild".
Build->Rebuild Project . Deleting gen does not do it since IDEA saves the actual generated R somewhere else.
In my case, I added some classes from another project and I had to add the import to the R package from my actual project:
import com.youcompanyname.yourprojectname.R;
I've started playing around with IntelliJ since I've had issues with the new Android Studio and wanted to try something that was a little more stable (I've never really used either before). I ended up getting the dreaded “package R does not exist” error. In my experience, this is usually something messed up in an XML file. For me, the problem was actually with the AndroidManifest.xml file for an Android Library Module that I had created for ActionBarSherlock. For whatever reason, when it created the AndroidManifest.xml file it didn't bother to use the AndroidManifest.xml file that came with ABS and it put the following in:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.ActionBarSherlockLibrary_4_3_1"
android:versionCode="1"
android:versionName="1.0">
<application
android:label="#string/app_name"
android:icon="#drawable/ic_launcher">
<activity
android:name="ACTIVITY_ENTRY_NAME"
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>
When I created this Module I chose File > New Module...
I then Selected Library Module under the Android section and for the Content Root I browsed to the location of the files for ABS (Other fields auto filled in correctly and I didn't change them).
I then clicked finish and it prompted me if I wanted to keep the local file or the memory file for project.properties.
I chose to keep the local file and it didn't prompt me for any others after that.
I have no idea why it messed up the AndroidManifest.xml file (maybe what I did above was wrong...???), but to fix it I just copied the original AndroidManifest.xml that I had downloaded with the library and replaced the messed up AndroidManifest.xml file. After that I did Build > Rebuild Project and it resolved the “package R does not exist” errors.
One other thought, #xbakesx mentions the Facets settings, and for any modules you are using as libraries, you should make sure that "Library module" is checked under Facets for that Module. I had some issues with that at first when I was trying to figure out how to configure libraries in IntelliJ/Android Studio (I've really only used Eclipse).
I just restart IntelliJ and it magically solved.
Try it first.
Had same issue - the issue was the Manifest file was did not have the default Activity setup properly.
To all the hopeless people who have reached this far down the answers: I feel your pain. I have spent an hour doing nothing but trying all those things above as well as proposals from other sources. I have checked all my xml resources twice, cleaned caches, rebuilt a dozen times, even restarted the entire machine. Here is what actually worked for me:
Under 'Build Variants' (lower left corner), I selected a different Build Variant (in my case release instead of debug) for the target that had the missing R problem. Solved it.
I've refactored the packagename and intellij didn't update it in the manifest.
So if you've refactored the packagename then go to the manifest and update the attribute "package" in the root of the xml file save and rebuild it. If any errors occur then it's probably a wrong packagename in the import (at least this was my case) so just fix them
hope this helps anyone
In my case I had to delete the intellj compiler cache. on my windows machine it was somelike this:
%USERPROFILE%\.IdeaIC12\system\compile-server\<my project>
Try create new project and select "Create project from existing sources"
Adding my $0.02 just in case someone else has the issue I did. In my case I had generated the "Hello world" application using IntelliJ and forgot to change the package name from "com.example." I then used IntelliJ to refactor the package name. This caused the error to start happening.
So I did a global search for "com.example" and it was found in the AndroidManifest file as mentioned by others. However, changing this did not fix the problem. "com.example" was also found in "workspace.xml" under the ".idea" directory. I changed all the occurrences their, did a rebuild and then it started working again!
This seems like a bug in IntelliJ.
In Android Studio, my problem was when i copy pasted a class to use as a template to make another similar class, it asks to automatically import a bunch of stuff, most of which was not going to be related to the new class, so i said cancel. with it it left out import com.your.packagename.R; so R wasnt actually being imported into the file i was trying to use it in.
can be fixed with an alt-enter when clicking on R (it should be highlighted in red)

ACRA - How to implement it into an existing project

Hi all first timer here,
I have a project I've been working on and now I wish to integrate ACRA into it. I downloaded the file from google, created a folder lib and imported the jar file into it. I added the INTERNET permission to the manifest, and created a MyApplication class with the suggested code from http://code.google.com/p/acra/wiki/BasicSetup into my package as stated in the instructions. Now that I have done all that how do i get it to take effect with my application and am I missing anything? Should I have not created a new class and just added the code into the existing main class?
Thanks for the help!
Now that I have done all that how do i get it to take effect with my application and am I missing anything?
If you followed the BasicSetup instructions per your link, then this work is already done.
Ok, so the issues was that firstly, I forgot to add android:name="MyApplication" in the application tag in the manifest. Secondly, for some reason for some systems the lib folder needs to be renamed "libs" and then path rebuilt, the process is detailed here: http://android.foxykeep.com/dev/how-to-fix-the-classdefnotfounderror-with-adt-17
Cheers

How to properly change the package name in AndroidManifest.xml (e.g. in project zxing/barcodescanner)

I'm pretty new to android development, so I hope my question is easy, but not completely stupid. I'm using Eclipse to build an android application. It is based on the barcode-scanner of the ingenious guys from zxing. I already did quite some changes to the original code and everything works fine. But I still have the problem, that the original barcode-scanner and my app cannot run simultaneously on one mobile device. As far as I could find out, the problem is the package name. So I tried to change it to something else. But that srew up my entire project, because I can't access my resources anymore (e.g. findViewById(R.id.btDone); <-- R cannot be resolved to a variable).
Can anyone tell me what else I have to change to make my code work again?
This the beginning of my AndroidManifest.xml where I tried to change the package name:
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.google.zxing.client.android"
...
I also found an interesting entry in build.properties: (?!)
application-package=com.google.zxing.client.android
Thanks you guys!
This should do it: Right Click on project -> Android Tools -> Rename Application Package
Android - Package Name convention
The package refers to the file directory you made. If you still have problems, especially with android, sometimes doing project->clean and then rebuilding fixes some of the linking problems with resources
Assuming you choose to go with the new package name:
com.superscanner.android
And with the old package name being (for example):
com.google.zxing.client.android
Go through all the source code and change:
import com.google.zxing.client.android.R;
To:
import com.superscanner.android.R;
You'll also have to rename all your directories to match your new package structure, and change your import and package statements throughout, but this should get you going.

app installations overwriting each other

I have developed two android apps...when i install them on my phone to test them.. they overwrite each other. I do not want this to happen. The intent is to have both installed on the phone as separate apps.. how do i fix this? I developed them with eclipse.
I had the same problem despite the fact that package names were different between both APKs.
At the end I had to modify a GRADLE file:
\app\build.gradle
the following line:
applicationId "name.to.change"
In Android Studio 3 you will find this configuration in:
I had the same issue, turned out that I had copied one project to another to save time, and the package setting in the Manifest tag inside the AndroidManifest.xml file was the same for both apps.
Once I changed this and resolved any imports errors, the apps stopped overwriting one another on the phone.
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="xxx.yyy"
android:versionCode="1"
android:versionName="1.0" >
Do the apps share the same namespace? Verify that they have their own packages in Eclipse.
also share the same user id, modify it in the manifest.

Categories

Resources