apache / cordova-android

Apache Cordova Android
https://cordova.apache.org/
Apache License 2.0
3.59k stars 1.52k forks source link

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

Closed wedgberto closed 1 year ago

wedgberto commented 3 years ago

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 https://github.com/apache/cordova-android/commit/3712619f5cd3de5055336e87bfade2bc2407900d#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:

<?xml version='1.0' encoding='utf-8'?>

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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

Same issue here

FredeX commented 5 months ago

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 commented 5 months ago

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 https://github.com/apache/cordova-android/compare/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 commented 2 months ago

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.