I'm trying to make my project modular on Eclipse, but I'm running into an issue. I have added the module-info.java file through right-clicking on the project > Configure > Create module-info.java. However, when I run, I get the error
Error occurred during initialization of boot layer
java.lang.module.FindException: Module serenitea-pot-manager not found
I believe this might be caused by having renamed the project to sereniteaPotManager at some point. Initially, the project name was serenitea-pot-manager, which is the name of the module being asked for. I did the renaming through right-clicking on the project > Refactor > Rename..., which should have updated all instances.
I have been searching for a while, but still haven't found a way to fix this. Is there anything else that I need to update on Eclipse for it to change to the correct module name?
Note: The module name included in module-info.java is indeed sereniteaPotManager.
I had the same problem. I will summarize my experience then my solution.
I did a rename of the module, and Eclipse kept wanting to use the old module name. Cleans, restarts, etc., did not help. A search of the project properties, the run configuration, and all files in the workspace, did not turn up an instance of the original module name. Editing the module name so that it matched the original one did work. It is as if Eclipse tucks away the initial module name in some hidden place and keeps wanting to use it.
I was able to solve the problem by deleting all Run configurations that existed and then creating a new project and new Run configuration.
I am using JavaFX, and a somewhat peculiar side-effect of this is that the normally-required run configuration argument (below) was not needed in this new run configuration. I wonder if Eclipse is tucking that away in some hidden place, also?
In Java, serenitea-pot-manager is an invalid module name since a module name must not contain hypens (-).
Therefore, In module-info.java, Eclipse shows Syntax error on token "-". So make sure, before running your application, no compile errors are shown in the Problems view.
Rename your module to serenitea_pot_manager, delete the existing launch configuration (in Run > Run Configurations...) and try again:
module serenitea_pot_manager {
// ...
}
https://stackoverflow.com/users/17416717/stevevzzz[Steves] solution worked for me while I got stuck with the same problem.
... but I did not create a new project. I only was able to solve the problem by deleting all Run Configurations that existed and then I created a new Run Configuration.
I noticed the same behaviour. After changing the module name of my project, I got the error
Error occurred during initialization of boot layer
java.lang.module.FindException: Module ... not found
It looks like eclipse holds on to the original module name that is used when first running the application using the Run Configuration. To work around this issue, I deleted and recreated the run configuration. Then it works again.
I guess I can't follow these instructions (but I've never used Eclipse before).
Here's my Eclipse Luna (2; 4.4.2) project structure, including a look at the file (SimpleIME.java) with the two errors (R cannot be resolved to a variable) (I have cleaned the project; rebuilding is automatic.):
There are two identical AndroidManifest.xml files. One that I created and one that Eclipse (or whatever) created.
The project has no Activity by design but Eclipse created one anyway, so I deleted it (with preview; only one reference (itself) was found).
Here's R.layout.keyboard:
Here's R.xml.qwerty:
So... what should I do? I cut and pasted entire contents of files and even file names, so typos shouldn't be the culprit, but maybe the structure is messed up. There's no structure shown at this otherwise excellent tutorial (first link).
Normally Eclipse and also Android Studio has problems to resolve the R resources if there is somewhere an exception.
Save all your classes and try to clean and build again. Normally it should give you an exception which resource is wrong. (Any image with wrong name, upper case name of image, any .xml file with exceptions.)
The cause is that the Android tools can only compile and create the R file if it is able to resolve all resources, and their identifiers.
If you tried clean and build. please post the error which will occur. (I made the experience that Eclipse has some issues to show the error marker on the specific resource file)
On a side note: Why do you still use Eclipse?
I am working on the Bluetooth Chat from the Android Developer site in
Eclipse IDE. I am using Android 2.1 and changed the Action Bar to
display Toast messages instead and am only working with Secure
connections.
I have three classes under the same package called BluetoothChat,
BluetoothChatService, and DeviceListActivity and the project name is
BluetoothCh.
Two of the files had errors that I fixed. They were saved and are
clear of the red x that previously marked both .java files. All of
the other files are clear of errors as well. However, the main
Android project folder still contains a red x, and Eclipse is not
allowing a run or debug of the application because of errors in
the project.
Does anyone have any ideas how to solve this? Any advice is very much
appreciated! Thank you!
Refresh the project then clean the project.
Delete the error in the "Problems" tab.
Right click the project->Android->Clean project properties (or whatever it is).
Clean the project and rebuild it see if the X mark still persists.
"When I clean the project it now gives me errors that R cannot be resolved as a variable. Where should I go from here?"
It sounds like you have an error in your code somewhere. You need to find out where the error is (what file and line) and fix it. This can be done with the problems tab in eclipse. It should tell you the description, file, path, line, and type of error you are getting.
I am trying to refactor my package using Eclipse
org.sheehan.activity
to
org.sheehan.stocks.activity
For some reason my project just blows up when I do this and R doesn't get regenerated. How can I refactor properly?
UPDATE:
I updated my Android Manifest to reflect the change. R still doesn't get regenerated. Even after a clean. The compiler is complaining about org.sheehan.activity.R
I resolved by:
Android Tools > Rename Package Application
If you renamed properly, all your references across your project should have gotten updated. After doing this, clean your project by going to Project > Clean. This should fix it.
Fixing missing reference to R in eclipse:
Refactor -> Rename`
Build -> Clean
Android Tools -> Fix Project Properties
select the base package of your project in the eclipse package explorer, press F2 (Rename), in the rename dialog: SELECT ALL the checkboxes.:
That should do it
The package name doesn't update in the XML files. Specifically your manifest which needs to know the base package.
For more advanced imports and refactors, literally closing the Eclipse IDE can refresh a cache that causes random errors like "End position lies outside document range" or the "what once worked now doesn't hair puller outter errors."
Signs you should close Eclipse when trying to rename things are:
When you import a project, do some refactoring (like trying to change the package name), then delete the project and try again, you will see immediate R.java errors when you didn't before
When you are importing projects that have manually generated R.java files that have custom imports like "com.ns.proj.R" and don't see the name update in Preview
The box that asks if you want to "Rename subpackages" is checked unexpectedly
the code in the "Preview>>" looks as if it's been complied before instead of black and white code with the proper names replaced
you get XML errors in the manifest activity name like this
android:name="com.ns.proj.CustomCocom.ns.proj.CustomControlse="#android:style/Theme.Light.NoTitleBar"
when it should be
android:name="com.ns.proj.CustomControls"
android:style="Theme.Light.NoTitleBar"
There are too many to name obviously, however this is as important as "keep your eye on the ball" in sports. Something that is so easy to forget, yet things like these apply to other software programs like Dreamweaver (e.g. when you use the Dreamweaver "Put" option instead of FTP dragging with FileZilla and you notice your domain isn't updating your changes online). I called Adobe when I first started as a developer 8 years ago because I knew I wasn't doing anything wrong. They said sometimes the generated files to perform the action get corrupted...in other words, IDE's have bugs too!
In general, close the IDE before you off yourself...it could save your life!
Right click in your Project, go to
Android Tools > Rename Package Application
Sometimes if Project > Clean doesn´t work, so Delete /gen and /bin folders of your project.
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