New location for AndroidManifest.xml in NativeScript 4?


#1

I updated NativeScript from 3.4.x to 4.0.2, attempted an Android build, and got errors regarding the google-maps-sdk map api key. OK, so I removed and re-added that plugin and follow the directions for adding the google maps api key, and those instructions point to several new locations that don’t exist in my upgraded project, namely,

app/App_Resources/Android/src/main/AndroidManifest.xml
 app/App_Resources/Android/src/main/res/values/nativescript_google_maps_api.xml

I’m trying to understand the context here. Has AndroidManifest.xml moved in TNS 4.0? Should the containing folders already exist?

Thanks for any pointers here.


#2

AndroidManifest did not move, I upgraded my project recently to NS 4.0.1 and did not move anything.


#3

@fthuin - I think you’re right. I created a new 4.0.2 project, added Android, and the folder layout and location of AndroidManifest.xml is the same as before. Notably, the folder /app/App_Resources/Android/src/main does not exist. Maybe this is just a google-maps-sdk plugin thing? Their 4.0 demo code does show those folders and a new location for AndroidManifest. I think, more likely, there’s some new feature for NativeScript 4.0 that I haven’t found documented yet.

Update: Just found this: https://github.com/NativeScript/android-runtime/issues/890


#4

So for anyone following this topic, there is a new folder structure for Android in NativeScript 4. The
tns resources update android command will migrate a project to use the new folder structure. See https://docs.nativescript.org/docs-cli/project/configuration/resources/resources-update.


#5

It might be NativeScript 4.1.0 that forces the new structure, because it looks like if I update, my project does not work anymore :frowning_face:


#6

I just upgraded to ns 4.1 and sure enough on android google maps plugin started giving runtime errors about api key not found.

Got it working again after following the instructions here. However, I had no app/App_Resources/Android/src/main/res path but I did have app/App_Resources/Android/values that already had the nativescript_google_maps_api.xml file inside it. So the only change I had to do was add

<meta-data
            android:name="com.google.android.geo.API_KEY"
            android:value="@string/nativescript_google_maps_api_key" />

to app/App_Resources/Android/AndroidManifest.xml

I don’t think AndroidManifest.xml moved, and maybe the instructions just contain incorrect paths?


#7

@jeffswitzer - Based on what I’ve found, here’s what you need to do to update a project from NativeScript 3.x to 4.x on Android that uses nativescript-google-maps-sdk:

Update NativeScript itself:

tns update

Update the platform:

tns platform remove android
tns platform add android

Update the plugins:

tns plugin update

Migrate to the new 4.0 directory structure on Android:

tns resources update android

Add the nativescript-google-maps-sdk meta-data to AndroidManifest.xml:

<meta-data
            android:name="com.google.android.geo.API_KEY"
            android:value="@string/nativescript_google_maps_api_key" />

Other variations can work, but this resulted in a structure that matches the sdk’s instructions, and worked for me.