Can i change signed android project package name? - java

I have an android project and the package is signed. When I want to change the package name, I get a "runtime exception" error. Is there any way to get rid of this signature?

If you are using Android Studio then use Refactoring instead of simply renaming Package Name. Right click on Package>Refactor>Rename.
Still better option is to create a new Project with your required Package Name and Copy all Java Classes and Resources to New Project.

Related

Error in renaming R3 Corda template package

I have cloned the 'Kotlin CorDapp Template' project. I am trying to rename the package from 'com.template' to 'com.new_name' through IntelliJ. Renaming happens, but I get an error while importing the changes - 'can't find resource for bundle java.util.PropertyResourceBundle, key kotlin.gradle.testing.enabled'. Please help.
This looks an error from the IDE.
Somehow it is easy to crash since there are two separate directory requires the same package name.
contracts
workflows
A work-around is to right-click on the net.corda.template on both directories and click refactor to rename it properly.

must declare a named package eclipse because this compilation unit is associated to the named module

I just downloaded eclipse for Java Yesterday but when I was trying to get make my first program, I kept on getting this error:
must declare a named package eclipse because this compilation unit is associated to the named module x.
How do I fix this?
Just delete module-info.java at your Project Explorer tab.
The "delete module-info.java at your Project Explorer tab" answer is the easiest and most straightforward answer, but
for those who would want a little more understanding or control of what's happening, the following alternate methods may be desirable;
make an ever so slightly more realistic application; com.YourCompany.etc
or just com.HelloWorld (Project name: com.HelloWorld and class name: HelloWorld)
or
when creating the java project; when in the Create Java Project dialog, don't choose Finish but Next, and deselect Create module-info.java file
Reason of the error: Package name left blank while creating a class. This make use of default package. Thus causes this error.
Quick fix:
Create a package eg. helloWorld inside the src folder.
Move helloWorld.java file in that package. Just drag and drop on
the package. Error should disappear.
Explanation:
My Eclipse version: 2020-09 (4.17.0)
My Java version: Java 15, 2020-09-15
Latest version of Eclipse required java11 or above. The module feature is introduced in java9 and onward. It was proposed in 2005 for Java7 but later suspended. Java is object oriented based. And module is the moduler approach which can be seen in language like C. It was harder to implement it, due to which it took long time for the release. Source: Understanding Java 9 Modules
When you create a new project in Eclipse then by default module feature is selected. And in Eclipse-2020-09-R, a pop-up appears which ask for creation of module-info.java file. If you select don't create then module-info.java will not create and your project will free from this issue.
Best practice is while crating project, after giving project name. Click on next button instead of finish. On next page at the bottom it ask for creation of module-info.java file. Select or deselect as per need.
If selected: (by default) click on finish button and give name for module. Now while creating a class don't forget to give package name. Whenever you create a class just give package name. Any name, just don't left it blank.
If deselect: No issue

BaseGame Util cannot be resolved to a type

my project requires BaseGameUtil library
I have BaseGameUtil library downloaded form here
But when i import it in my android project it doesnt show baseGameUtil instead it shows main as added in my eclipse project and even when i add that main library i still get the same error.
Can anyone help me.
I think you may be using the version of BaseGameUtils in here:
...\android-samples-master\BasicSamples\libraries
But you are using Eclipse so you need to use the one in the following location:
...\android-samples-master\eclipse_compat\libraries
You may then also encounter an error with the GameHelper.java class in the BaseGameUtils folders. Use the code available here instead: https://gist.github.com/EmmanuelVinas/ef09a35bcc805ba6deb3
BaseGameActivity cannot be resolved to a type
public Class FisrstActivity extends BaseGameActivity{
In your project, right click > properties > Android > in Library section check if your library is correct and donĀ“t show any red cross.
Check the same for your BaseGameUtils library, probably the reference to google_play_services is incorrect.
you problem must be similar to : android - import - with developers google com games
Basegameutils from github includes all source .java files in java folder. When implementing in eclipse, move all these folders from 'java' to 'src'. Eclipse compiles them to produce .class files which fixes this problem.

R.layout.main couldn't be resolved

I am building an application and I added a new activity to generate a view. I compiled it. My application can not find anything that is on the format R.id.xxx or R.layout.xxx, I've tried also cleaning my project, closing Eclipse and opening Eclipse again, but nothing. The most strange thing is that before everything was working well. But now it can not recognize even the R.layout.main that is default of my principal activity. Anyone have an idea?
Also I have tried almost everything here: R cannot be resolved - Android error
but no result!
Solved
Thanks to woopsy, also I found the reference to this kind of problem
http://source.android.com/source/using-eclipse.html
it happens because Eclipse sometimes imports R when you press the combination ctrl+shift+O
Remove all your imports for the Activity and then have eclipse fix imports. I have had problems where eclipse wants to import a different R than the one I need.
First of All Check You have R.java File then check
import android.R;
Enter Yourpackages like import com.mypackages.prj;
If you are using eclipse, take a backup of your layout main.xml file and then from the eclipse new file interface create a new "Android XML File" and call it main.xml. copy back from the backup the contents into this new file.
try this.
check your xml files. there might be something wrong in it which is causing R not to build up automatically. To observe such errors, switch your view to Console tab
this is a common error. You need to just search your R.java file in generated section of your project directory in Eclipse. Need to import if the R.java file into the package then import . R;
I hope it will work for you. It was absolutely worked for me...enjoy programming
friends take care that u haven't imported R class, if you have delete "import android.R". The reason is there are two R things one R.java and R.class and we need the java, where we dont need to import rather than referring it. It worked for me and may be to you too.
I found the solution...For me works it
Poject->Properties->Android->Project Build Target (here choose android4.4 or 5.1.1 Android Open Source Project)->Ok
Project->Build All
This function ...
This problem can fix with this process: -
File---->Invalidate cache/restart.
it will restart your android studio and fix that problem

How to change package name of an Android Application

My keystore is corrupt, therefore the Android Market is requiring me to rename the app and resubmit it. However, whenever I go to edit the package names in Manifest and throughout the files, it gives me tons of errors.
What's the proper way to change the application name?
There is a way to change the package name easily in Eclipse. Right click on your project, scroll down to Android Tools, and then click on Rename Application Package.
If you're using Eclipse, you could try these instructions from Android's developer site. They're specifically for the GestureBuilder sample but should apply to any application as far as I can tell:
[H]ere's how you could do this in Eclipse:
Right-click on the package name (src/com.android.gesture.builder).
Select Refactor > Rename and change the name, for example to
com.android.gestureNEW.builder.
Open the manifest file. Inside the
<manifest> tag, change the package name to
com.android.gestureNEW.builder.
Open each of the two Activity files
and do Ctrl-Shift-O to add missing import packages, then save each
file. Run the GestureBuilder application on the emulator.
Also, be sure you remembered to rename the package itself along with the references to it in the files. In Eclipse you can see the name of the package in the file explorer window/tree view on the left hand side. In my experience, Eclipse can sometimes be a little finnicky and unreliable with this (leaving behind stray references to the old package name, for example).
Here's how you could do this in Eclipse:
Right-click on the package name (src/com.android.gesture.builder).
Select Refactor > Rename and change the name, for example to
com.android.gestureNEW.builder.
Open the manifest file. Inside the <manifest> tag, change the package name to com.android.gestureNEW.builder.
Open each of the two Activity files and do Ctrl+Shift+O to add missing import packages, then save each file.
Run the GestureBuilder application on the emulator.
Link to post
Update
super easy way
right click on your project...
In Android Studio, which, quite honestly, you should be using, change the package name by right-clicking on the package name in the project structure -> Refactor -> Rename...
It then gives the option of renaming the directory or the package. Select the package. The directory should follow suit. Type in your new package name, and click Refactor. It will change all the imports and remove redundant imports for you. You can even have it fix it for you in comments and strings, etc.
Lastly, change the package name accordingly in your AndroidManifest.xml towards the top. Otherwise you will get errors everywhere complaining about R.whatever.
Another very useful solution
First create a new package with the desired nameby right clicking on thejava folder -> new -> package.`
Then, select and drag all your classes to the new package.
AndroidStudio will re-factor the package name everywhere.
After that: in your app's build.gradle add/edit applicationId with the new one. i.e. (com.a.bc in my case):
defaultConfig {
applicationId "com.a.bc"
minSdkVersion 13
targetSdkVersion 19
}
Original post and more comments here
Without Eclipse:
Change package name and Activity names in AndroidManifext.xml and anywhere else it shows up in .xml files (custom view names, etc)
Update package import statement across all source files
Rename all folders to match the package name. Folder locations:
a. bin/classes
b. gen
c. src
Update the project name in build.xml (or your apk's name won't change)
Delete all the .class files in bin/classes/com/example/myapp/ (if you skip this step the files don't get rewritten during build and dex give a bunch of trouble processing "class name does not match path" errors
Delete gen/com/example/myapp/BuildConfig.java (I don't know why deleting BuildConfig.class in step 3a didn't cause dex to update it's path to this, but until I deleted BuildConfig.java it kept recreating gen/com/oldapp_example/oldapp and putting BuildConfig.class in there. I don't know why R.java from the same location doesn't have this problem. I suspect BuildConfig.java is auto-generated in pre-compile but R.java is not)
The above 6 steps are what I did to get my package name changed and get a successful* build. There may be a better way to handle steps 5 and 6 via dex commands to update paths, or perhaps by editing classes.dex.d in the root directory of the project. I'm not familiar with dex or if it's ok to delete/edit classes.dex.d so I went with the method of deleting .class files that I know will be regenerated in the build. I then checked classes.dex.d to see what still needed to be updated.
*No errors or warnings left in my build EXCEPT dex and apkbuilder both state "Found Deleted Target File" with no specifics about what that file is. Not sure if this shows up in every build, if it was there before I messed with my package name, or if it's a result of my deletions and I'm missing a step.
Follow these steps:-
Right click on the project.
Go to Android tools.
Click on Rename Application Package.
Change the application package name.
DONE
The fastest way to do that in Android Studio 1.3:
Change the package name in the manifest
Go to Module Settings[F4]-> Flavors, into Application Id write the same name.
Create new package with that name: [right-click-> new-> package]
Select all java files of your project and then proceed [Right-click-> Refactor-> Move-> {Select package}-> Refactor]
P.S. If you will not follow this order you can end up changing all the java files one by one with new imports and a bunch of compile time errors, so the order is very important.
Changing package name is a pain in the ass. It looks like different methods work for different people. My solution is quick and error free. Looks like no cleaning or resetting eclipse is needed.
Right click on the package name then Refractor > Rename.
Right click on the project name Android tools > Rename Application Package.
Manually set the package names in the Manifest that have not been changed by the previous steps.
Bernstein has the method, use the Eclipse tool, "Rename Application Package", you may have to do some clean-up even after the fact.
Also, Eclipse sometimes loses track of things when you make changes to a project. You may have to use the "Clean Project" tool (under the "Project" menu.) If that doesn't work, you may have to close and restart Eclipse. Voo-doo solutions, but Eclipse can be that way.
I found the easiest solution was to use Regexxer to replace "com.package.name" with "com.newpackage.name", then rename the directories properly. Super easy, super fast.
Fist change the package name in the manifest file
Re-factor > Rename the name of the package in src folder and put a tick for rename subpackages
That is all you are done.
There is also another solution for users without Eclipse, simply change the package attribute in <manifest> tag in AndroidManifest.xml, by replacing the the old package name used with a new one. Note: You have to adjust the all the related import statements and related folders manually in your project than, too.
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="new.package.name"
.....
</manifest>
In Android Studio 1.2.2
Say if you want to change com.example.myapp to org.mydomain.mynewapp
You can follow the steps in each of the directories as displayed in the below screen shot. It will give you the preview option so that you can preview before making any changes.
Go to Refactor -> Rename and give your new name. You have to do it for each of the folders, say for com, example and myapp. It will automatically update the imports so that you don't have to worry about it.
Also update the file build.gradle which is not updated automatically.
defaultConfig {
applicationId "org.mydomain.mynewapp" //update the new package name here
minSdkVersion 15
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
After that it will ask for sync do it. Then everything will be fine. I'm able to upload my APK to google store after this. Make sure you have signed your app to upload it to the store.
Alternative:
Open AndroidManifest.xml
Change package="NEW NAME" within manifest tag.
Right Click on Project >Android Tools >Rename Application Package
Go to src and right click on your main package >Refactor >Rename
Go to manifest file and change your package name .
I just lost few hours trying all solutions. I was sure, problem is in my code - apk starting but some errors when working with different classes and activities.
Only way working with my project:
rename it - file/rename and check all checkboxes
check for non renamed places, I had in one of layout old name still in tools:context="..
create new workspace
import project into new workspace
For me it works, only solution.
So, using IntelliJ with Android (Studio) plugin was: I went to AndroidManifest.xml on top and changed package name by right-clicking -> Refactor -> rename.
Our then package name had four parts a.b.c.d, the new one only a.b.c.
So I renamed the first three. Then I went to the directory of generated sources (app\build\generated\source\r\development\debug\a\b\c\d), right-clicked R class and Refactor->Move[d] it to one package higher. Same with BuildConfig in app\build\generated\source\buildConfig\development\debug\a\b\c\d.
By using Refactor->Move, IntelliJ updates all references to BuildConfig and R.
Finally I updated all applicationId[s] I found in gradle.build I found. I hit Clean Project, Make and Rebuild Project. Deleted the app from my phone and hit "Play". It all worked out so refactoring was easy and quite fast.
In your Android studio , at project panel , there is gear icon "Click on it".
Uncheck the Compact Empty Middle Packages
Now the package directory has been broken up i.e individual directories.
Select the directory you want to rename.
Right click on that particular directory.
Select refactor and then rename option.
The dialog box has been open up,rename it.
After putting new name, click on Refactor.
Then click on Do Refactor at bottom.
Then android studio will update all changes.
Now open build.gradle file and update the applicationId & sync it.
Now go to manifest file and rename the package.
Rebuild your Project.
You are done :)
If you are looking for a quick and safe solution to change the package name, then I suggest you use the plugin "Android Package Renamer", It is available on Android Studio Market.
What you need to do is
enter "Your package name you want to change"
Click OK.
You can see the detailed answer here

Categories