Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MainActivity.java file deleted on build when package name is changed in config.xml #1139

Closed
wedgberto opened this issue Dec 2, 2020 · 6 comments · Fixed by #1154
Closed

Comments

@wedgberto
Copy link
Contributor

Bug Report

Problem

MainActivity.java file is deleted when the package name changes

What is expected to happen?

When the package name is changed in config.xml, the MainActivity.java file is moved to the correct namespace path following the package name (E.g. io.cordova.hellocordova => io/cordova/hellocordova)
This allows an app to be built with different package names so it can be installed side by side on a device.

What does actually happen?

The MainActivity.java file that exists for the previous package name gets deleted and a new one in the path for the new package name is not created.

Information

changing the package name of the app in the config.xml between builds results in the android platform folder becoming broken because the MainActivity.java file gets deleted. It is only created when the platform is added.

I commented on the commit that broke this. Package name changes were supported in 8.1.0. see 3712619#r43030914

Command or Code

cordova create myApp
cd myApp
cordova platform add android

this results in the file platforms/android/app/src/java/io/cordova/hellocordova/MainActivity.Java being generated

cordova run android

hello cordova app builds and runs on device
edit config.xml -> change package name to io.cordova.goodbyecordova

cordova run android

hello cordova app builds but crashes when launched on device.

cordova run android

No Java files found that extend CordovaActivity.

Environment, Platform, Device

Windows 10 developer machine.
Android target platform.

Version information

Cordova Packages:

cli: 10.0.0
    common: 4.0.2
    create: 3.0.0
    lib: 10.0.0
        common: 4.0.2
        fetch: 3.0.0
        serve: 4.0.0

Project Installed Platforms:

android: 9.0.0

Project Installed Plugins:

cordova-plugin-whitelist: 1.3.4

Environment:

OS: Microsoft Windows 10 Pro 10.0.18363 (18363) (win32 10.0.18363) x64
Node: v10.16.3
npm: 6.14.9

android Environment:

android:

The "android" command is deprecated.
For manual SDK, AVD, and project management, please use Android Studio.
For command-line tools, use tools\bin\sdkmanager.bat
and tools\bin\avdmanager.bat


Invoking "C:\dev\android-sdk\tools\bin\avdmanager" "list" "target"

Loading local repository...
[========= ] 25% Loading local repository...
[========= ] 25% Fetch remote repository...
[========= ] 25% Fetch remote repository...
[========= ] 25% Fetch remote repository...
[=======================================] 100% Fetch remote repository...
Available Android targets:

id: 1 or "android-28"
Name: Android API 28
Type: Platform
API level: 28
Revision: 6

id: 2 or "android-29"
Name: Android API 29
Type: Platform
API level: 29
Revision: 5

id: 3 or "android-30"
Name: Android API 30
Type: Platform
API level: 30
Revision: 3

Project Setting Files:

config.xml:
HelloCordova A sample Apache Cordova application that responds to the deviceready event. Apache Cordova Team
package.json:

--- Start of Cordova JSON Snippet ---
{
"plugins": {
"cordova-plugin-whitelist": {}
},
"platforms": [
"android"
]
}
--- End of Cordova JSON Snippet ---

Checklist

@Davilink
Copy link

Davilink commented Jun 8, 2021

The workaround is to remove all platform and re-adding them before a cordova build. It works, but it's take longer to make build.

@wedgberto
Copy link
Contributor Author

The workaround is to remove all platform and re-adding them before a cordova build. It works, but it's take longer to make build.

Yes, and the package name has to be changed before re-adding the android platform. I'd rather not have to do this because it takes longer to rebuild like you say

@Fourie-r
Copy link

Fourie-r commented Dec 3, 2021

Same issue here

@FredeX
Copy link

FredeX commented Dec 6, 2023

Sorry to dig up this issue but i'm having this problem again with cordova-android@12.0.0. If I downgrade to 11.0.0 (the release where its been fixed) it's working absolutely fine. Is there a reason why v12 reintroduced this "bug"?
Hope someone can help

@breautek
Copy link
Contributor

Sorry to dig up this issue but i'm having this problem again with cordova-android@12.0.0. If I downgrade to 11.0.0 (the release where its been fixed) it's working absolutely fine. Is there a reason why v12 reintroduced this "bug"? Hope someone can help

The changes between v11 and v12.0.1 can be found at rel/11.0.0...12.0.1

though nothing really stands out of why this may have regressed. If it did I'd recommend creating a new issue so we can track it appropriately.

@Methuselah96
Copy link

Methuselah96 commented Feb 13, 2024

Can confirm that this does not seem to be working. For me the destFile and newDestFile are equivalent (both are the old file path), so the moving/renaming code never gets triggered. I wasn't able to get cordova-android@11 working to determine if it was a regression or just never working.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
6 participants