NativeScript / android

NativeScript for Android using v8
https://docs.nativescript.org/guide/android-marshalling
Apache License 2.0
530 stars 135 forks source link

Package in AndroidManifest.xml set to incorrect "com.tns.testapplication" value after upgrade to @nativescript/android 8.8.0 #1815

Closed SeanGriffin-Wellsky closed 4 months ago

SeanGriffin-Wellsky commented 4 months ago

Environment Provide version numbers for the following components (information can be retrieved by running tns info in your project folder or by inspecting the package.json of the project): ✔ Getting NativeScript components versions information... ✔ Component nativescript has 8.8.0 version and is up to date. ✔ Component @nativescript/core has 8.8.1 version and is up to date. ✔ Component @nativescript/ios has 8.8.1 version and is up to date. ✔ Component @nativescript/android has 8.8.0 version and is up to date.

Describe the bug

After upgrading my local installation of NS to 8.8.0 and upgrading my project to use @nativescript/android 8.8.0, when running ns run android --emulator I get this output to my console:

webpack 5.92.1 compiled with 1 warning in 37206 ms
Webpack compilation complete. Watching for file changes.
Updating runtime package.json with configuration values...
Project successfully prepared (android)
Installing on device emulator-5554...
Successfully installed on device with identifier 'emulator-5554'.
Application com.wellsky.resourcemanager is not running on device emulator-5554.
This issue may be caused by:
    * crash at startup (try `ns debug android --debug-brk` to check why it crashes)
    * different application identifier in your package.json and in your gradle files (check your identifier in `package.json` and in all *.gradle files in your App_Resources directory)
    * device is locked
    * manual closing of the application
Unable to apply changes on device: emulator-5554. Error is: Application com.wellsky.resourcemanager is not running.

However, despite the above saying the application is not running on the emulator, it is running and functions correctly.

After looking at the code in https://github.com/NativeScript/android/commit/d4b716427934ebb4387a04842561d5b5d0e1fa3d I see a new computeNamespace function was added that looks suspicious, hard-coding the namespace that's returned to "com.tns.testapplication" when one isn't found. I searched my platforms/android build output dir for "com.tns.testapplication" and find that the package attribute in the AndroidManifest.xml is set to "com.tns.testapplication" rather than the ID I've specified in the nativescript.config.ts file; it should be "com.wellsky.resourcemanager".

I believe the issue is that the computeNamespace function is not handling the case where the "id" is defined under the "android" section in the nativescript.config.ts file rather than at the root. Indeed if I add this "id" field I'm able to work around the problem.

nativescript.config.ts that exposes the problem

export default {
  appPath: 'src',
  appResourcesPath: 'App_Resources',
  android: {
    id: 'com.wellsky.resourcemanager',
    v8Flags: '--expose_gc',
    markingMode: 'none'
  },
  ios: {
    id: 'com.wellsky.resource-manager'
  }
} as NativeScriptConfig;

nativescript.config.ts that works around the problem

export default {
  id: 'com.wellsky.resourcemanager',
  appPath: 'src',
  appResourcesPath: 'App_Resources',
  android: {
    id: 'com.wellsky.resourcemanager',
    v8Flags: '--expose_gc',
    markingMode: 'none'
  },
  ios: {
    id: 'com.wellsky.resource-manager'
  }
} as NativeScriptConfig;

Additional questions:

SeanGriffin-Wellsky commented 4 months ago

Same as https://github.com/NativeScript/NativeScript/issues/10587, which was fixed in 8.8.2. Closing.