简体   繁体   中英

Issue running more than one NativeScript application on the same android device with tns run

NativeScript 2.0.0, Windows 10

When trying to run more than one NativeScript application on the same android device the tns run android command stops with message:

Successfully deployed on device with identifier '192.168.99.100:5555'.

The application is not installed.

After some investigation, I tried to install the app on the android device using adb directly:

adb "-s" "192.168.99.100:5555" "install" "-r" "<path to apk>.apk"

The command responds with the following:

961 KB/s (15394490 bytes in 15.642s)
WARNING: linker: /system/lib/libhoudini.so has text relocations. This is wasting memory and prevents security hardening. Please fix.
        pkg: /data/local/tmp/<app name>-debug.apk
Failure [INSTALL_FAILED_CONFLICTING_PROVIDER]

After some investigation on INSTALL_FAILED_CONFLICTING_PROVIDER and found the following links:

I can say it's an ugly problem.

Researching some more, in the NativeScript project, in the directory \\platforms\\android\\build\\intermediates\\exploded-aar\\com.google.android.gms\\play-services-measurement\\8.4.0 directory there is a manifest template that contains:

<provider
      android:authorities="${applicationId}.google_measurement_service"
      android:name="com.google.android.gms.measurement.AppMeasurementContentProvider"
      android:exported="false"/>

But applicationId is never defined, so when more than one app with this provider is added, the second one fails to install.

I have multiple NS apps installed on my phone and emulators; however when you create a new app; check to see if somehow you have ended up with the same internal name. (This can easily happen if you duplicate your prior project)

Open up your main/primary package.json file that resides in the outermost root of your project folder.

Inside this package.json file you should have a key:

"nativescript": {
        "id": "org.nativescript.test3",
        "tns-android": {
            "version": "2.0.0"
        }
    },

The "id" is the underlying name of the app that will be installed on the phone. In this case; this is the awesome "org.nativescript.test3" project.

If you get duplicate id's then the the app will overwrite the each other when deployed.


There is a second reason this can happen, and the actual cause of this issue was figured out by the author of the question also. But I will stick here for any future people who might run into this so that we have a valid answer.

The author was using Google Play Services plugin, it has a AppMeasurementContentProvider that if you don't have a applicationId set in your configuration it will default to a blank id; which then means it will conflict with any other app that is using GPS that also doesn't have a applicationId set.

The real nastyness of this bug is that it will conflict with ANY app from ANY other developer who also left their applicationId blank. And so then only ONE of the apps would be installable; any other app that has a blank applicationId would not be installable on that device.

The solution is to open up your /app/App_Resources/Android/app.gradle file and we will add a new value to it.

The current version as of NativeScript v2.00 looks something like this:

android {  
  defaultConfig {  
    generatedDensities = []  
  }  
  aaptOptions {  
    additionalParameters "--no-version-vectors"  
  }  
} 

If you recall the first part of this answer and about duplicate ids; the package.json we referenced gives you the name you want to use. So in my case I would add to the

defaultConfig {
   applicationId = "org.nativescript.test3"
}

So the final file should look something like this:

android {  
  defaultConfig {  
    generatedDensities = []  
    applicationId = "org.nativescript.test3"
  }  
  aaptOptions {  
    additionalParameters "--no-version-vectors"  
  }  
} 

This is related to: Install shows error in console: INSTALL FAILED CONFLICTING PROVIDER https://code.google.com/p/analytics-issues/issues/detail?id=784

This workaround worked for me:

in the app/App_Resources/Android/AndroidManifest.xml file add:

<provider
   tools:replace="android:authorities"
   android:name="com.google.android.gms.measurement.AppMeasurementContentProvider"
   android:authorities="MY_APPLICATION_ID.gms.measurement.google_measurement_service"  
   android:exported="false" />

Where MY_APPLICATION_ID is the application's package (put it manually because __PACKAGE__ didn't work) Don't forget to declare de tools namespace:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="__PACKAGE__" ...>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM