Changing app id makes "tns run android" fail (I think)


#1

Hi guys, I have this app I’ve been working on for a few days.

I work / commit / push, etc. and, at some point, the app stopped working on Android when using “tns run android” (but it built fine if I built a release version with keystore, etc.).

The app installed in the emulator, but it crashed at launch with a “NativeScriptException: Application entry point file not found” error. That drove me nuts for a few days… It worked fine on iOS (emulated or in the actual device), it could be built and installed on an Android device, but I couldn’t emulate and work.

I tried the usual: deleting the hooks / node_modules / platforms folders (after tns platform remove android), then tns install / tns run android.

Nothing, the problem persisted.

So I reverted to previous commits to see if I had screwed something (the most likely possibility…) I chased the error for a few minutes (hours?) until I hit a seemingly trivial change: I changed the app id on the package.json file.

Originally it was something like:

“nativescript”: {
“id”: “org.nativescript.starterkitnativescript”
}

and I had changed it to

“nativescript”: {
“id”: “com.keetup.starterkitnativescript”
}

I reverted that line to its original state, ran tns run android, and everything worked just fine.

So, my actual question is: how can I change the app id and keep working? What is it breaking?

I tried disabling a few plugins, but nothing. I’m only using the side drawer from telerik and nativescript-localize from http://plugins.nativescript.org/plugin/nativescript-localize (I suspected the last one may have something to do).

Any leads?


#2

You would also have to make the change in the app.gradle file in your Android resources. The CLI takes your nativescript.id entry and attempts to start the app on the device with that name, while it in fact has the one registered by the gradle configuration.


#3

Great! Now it works.

Is there a way to do that automatically? I mean, is there a command, or a right way to do this, except editing package.json and app.gradle?

I think “tns init” might do, but I’m not sure.


#4

It is indeed a bit strange that this is not propagated automatically to the app.gradle file…


#5

We’ve had a few discussions in the team about that, and we still have no answer. There are several things to take into consideration like - you might want 2 different ids - 1 for android, another for iOS; after the initial setup of your app.gradle, parsing it becomes close to impossible - the Groovy syntax is very loose; the user may not want to have his app.gradle’s id changed, but that in the package.json instead. So which one should stay?

Make sure to catch up on https://github.com/NativeScript/nativescript-cli/issues/2089 and the follow-up issue. All of them cite great points.


#6

Oh, I see.

Is this details on the documentation? May be we should add it if it isn’t.

I usually use the same ID for both Android and iOS.