dapriett / nativescript-google-maps-sdk

Cross Platform Google Maps SDK for Nativescript
MIT License
244 stars 164 forks source link

AndroidX Issue??? #345

Open 18clans opened 5 years ago

18clans commented 5 years ago

Not sure what this issue is about but I just noticed this error started this morning. Could be AndroidX related. I tried building an empty NativeScript project and it built fine. Once I added a Google plugin, I get this error.

Error

tns info ✔ Getting NativeScript components versions information... ⚠ Update available for component nativescript. Your current version is 5.4.0 and the latest available version is 5.4.1. ✔ Component tns-core-modules has 5.4.2 version and is up to date. ✔ Component tns-android has 5.4.0 version and is up to date. ✔ Component tns-ios has 5.4.2 version and is up to date.

package.json { "nativescript": { "id": "org.nativescript.NSHelloWorld", "tns-android": { "version": "5.4.0" }, "tns-ios": { "version": "5.4.2" } }, "description": "NativeScript Application", "license": "SEE LICENSE IN ", "repository": "", "dependencies": { "@angular/animations": "~8.0.0", "@angular/common": "~8.0.0", "@angular/compiler": "~8.0.0", "@angular/core": "~8.0.0", "@angular/forms": "~8.0.0", "@angular/http": "~8.0.0-beta.10", "@angular/platform-browser": "~8.0.0", "@angular/platform-browser-dynamic": "~8.0.0", "@angular/router": "~8.0.0", "nativescript-angular": "~8.0.0", "nativescript-google-maps-sdk": "^2.7.0", "nativescript-theme-core": "~1.0.4", "reflect-metadata": "~0.1.12", "rxjs": "~6.5.0", "tns-core-modules": "~5.4.0", "zone.js": "~0.9.1" }, "devDependencies": { "@angular/compiler-cli": "~8.0.0", "@ngtools/webpack": "~8.0.0", "nativescript-dev-typescript": "~0.10.0", "nativescript-dev-webpack": "~0.24.0" }, "gitHead": "8c1a4866a66daab09bf5ef8e5a96472687192373", "readme": "NativeScript Application" }

18clans commented 5 years ago

Related link:

https://stackoverflow.com/questions/56654315/androidx-suddenly-causing-build-failure-for-nativescript

jcoronar22 commented 5 years ago

I have the same issue, buddy. Any comment is helpful

18clans commented 5 years ago

The issue why we're having this issue today is because Google released a new version of Google Play Services (breaking change).

You will have to migrate your plugins in NativeScript to support AndroidX.

The temporary fix is to use Google Play Service version 15.0.0.

Create a before-plugins.gradle in the same directory as app.gradle inside App_Resources > Android and use the code below.

before-plugins.gradle

android {  
  project.ext {
      googlePlayServicesVersion = "15.0.0"
  }
} 

Make sure you add this in the AndroidManifest.xml inside <application> tag.

AndroidManifest.xml

<application>
...
...
<uses-library android:name="org.apache.http.legacy" android:required="false"/>
...
...
</application>

I had to delete my platforms folder first before doing a tns build/run android --bundle again. Try this out and let me know if this fixes your problem.

david-mart commented 5 years ago

@18clans saved my day. spent unnecessary 2 hours of debugging just to find which plugin was erroring out

dungfv commented 5 years ago

I lost all day yesterday to check each plugin for this error. Happy tears

kaspervm commented 5 years ago

Having the same problem. Using Google Play Service version 15.0.0. Gives me another error:

06-19 12:57:35.002 19355 19484 E AndroidRuntime: FATAL EXCEPTION: Thread-21 06-19 12:57:35.002 19355 19484 E AndroidRuntime: Process: nl.waarneemhulp.app, PID: 19355 06-19 12:57:35.002 19355 19484 E AndroidRuntime: java.lang.NoClassDefFoundError: Failed resolution of: Lorg/apache/http/ProtocolVersion; 06-19 12:57:35.002 19355 19484 E AndroidRuntime: at gt.b(:com.google.android.gms.dynamite_mapsdynamite@17455084@17.4.55 (100700-248795830):3) 06-19 12:57:35.002 19355 19484 E AndroidRuntime: at gu.a(:com.google.android.gms.dynamite_mapsdynamite@17455084@17.4.55 (100700-248795830):3) 06-19 12:57:35.002 19355 19484 E AndroidRuntime: at gw.a(:com.google.android.gms.dynamite_mapsdynamite@17455084@17.4.55 (100700-248795830):14) 06-19 12:57:35.002 19355 19484 E AndroidRuntime: at com.google.maps.api.android.lib6.drd.aj.a(:com.google.android.gms.dynamite_mapsdynamite@17455084@17.4.55 (100700-248795830):6) 06-19 12:57:35.002 19355 19484 E AndroidRuntime: at fy.a(:com.google.android.gms.dynamite_mapsdynamite@17455084@17.4.55 (100700-248795830):22) 06-19 12:57:35.002 19355 19484 E AndroidRuntime: at fy.run(:com.google.android.gms.dynamite_mapsdynamite@17455084@17.4.55 (100700-248795830):8) 06-19 12:57:35.002 19355 19484 E AndroidRuntime: Caused by: java.lang.ClassNotFoundException: Didn't find class "org.apache.http.ProtocolVersion" on path: DexPathList[[zip file "/data/user_de/0/com.google.android.gms/app_chimera/m/0000000d/MapsDynamite.apk"],nativeLibraryDirectories=[/data/user_de/0/com.google.android.gms/app_chimera/m/0000000d/MapsDynamite.apk!/lib/x86, /system/lib]] 06-19 12:57:35.002 19355 19484 E AndroidRuntime: at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134) 06-19 12:57:35.002 19355 19484 E AndroidRuntime: at java.lang.ClassLoader.loadClass(ClassLoader.java:379) 06-19 12:57:35.002 19355 19484 E AndroidRuntime: at ab.loadClass(:com.google.android.gms.dynamite_dynamiteloader@17455084@17.4.55 (100700-248795830):4) 06-19 12:57:35.002 19355 19484 E AndroidRuntime: at java.lang.ClassLoader.loadClass(ClassLoader.java:312) 06-19 12:57:35.002 19355 19484 E AndroidRuntime: ... 6 more

OPADA-Eng commented 5 years ago

@18clans Can you please share your app.gradle file content ? I have the same problem but your solution didn't solve it. :(

18clans commented 5 years ago

@OPADA-Eng I created an empty NativeScript Angular project and added Google Maps SDK plugin. Here is my repo.

https://github.com/18clans/NS-HelloWorld

18clans commented 5 years ago

Having the same problem. Using Google Play Service version 15.0.0. Gives me another error:

06-19 12:57:35.002 19355 19484 E AndroidRuntime: FATAL EXCEPTION: Thread-21 06-19 12:57:35.002 19355 19484 E AndroidRuntime: Process: nl.waarneemhulp.app, PID: 19355 06-19 12:57:35.002 19355 19484 E AndroidRuntime: java.lang.NoClassDefFoundError: Failed resolution of: Lorg/apache/http/ProtocolVersion; 06-19 12:57:35.002 19355 19484 E AndroidRuntime: at gt.b(:com.google.android.gms.dynamite_mapsdynamite@17455084@17.4.55 (100700-248795830):3) 06-19 12:57:35.002 19355 19484 E AndroidRuntime: at gu.a(:com.google.android.gms.dynamite_mapsdynamite@17455084@17.4.55 (100700-248795830):3) 06-19 12:57:35.002 19355 19484 E AndroidRuntime: at gw.a(:com.google.android.gms.dynamite_mapsdynamite@17455084@17.4.55 (100700-248795830):14) 06-19 12:57:35.002 19355 19484 E AndroidRuntime: at com.google.maps.api.android.lib6.drd.aj.a(:com.google.android.gms.dynamite_mapsdynamite@17455084@17.4.55 (100700-248795830):6) 06-19 12:57:35.002 19355 19484 E AndroidRuntime: at fy.a(:com.google.android.gms.dynamite_mapsdynamite@17455084@17.4.55 (100700-248795830):22) 06-19 12:57:35.002 19355 19484 E AndroidRuntime: at fy.run(:com.google.android.gms.dynamite_mapsdynamite@17455084@17.4.55 (100700-248795830):8) 06-19 12:57:35.002 19355 19484 E AndroidRuntime: Caused by: java.lang.ClassNotFoundException: Didn't find class "org.apache.http.ProtocolVersion" on path: DexPathList[[zip file "/data/user_de/0/com.google.android.gms/app_chimera/m/0000000d/MapsDynamite.apk"],nativeLibraryDirectories=[/data/user_de/0/com.google.android.gms/app_chimera/m/0000000d/MapsDynamite.apk!/lib/x86, /system/lib]] 06-19 12:57:35.002 19355 19484 E AndroidRuntime: at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134) 06-19 12:57:35.002 19355 19484 E AndroidRuntime: at java.lang.ClassLoader.loadClass(ClassLoader.java:379) 06-19 12:57:35.002 19355 19484 E AndroidRuntime: at ab.loadClass(:com.google.android.gms.dynamite_dynamiteloader@17455084@17.4.55 (100700-248795830):4) 06-19 12:57:35.002 19355 19484 E AndroidRuntime: at java.lang.ClassLoader.loadClass(ClassLoader.java:312) 06-19 12:57:35.002 19355 19484 E AndroidRuntime: ... 6 more

Kaspervm do you have some sample code to share?

18clans commented 5 years ago

I'm getting the same error as Kaspervm when I tried rendering the Google Maps. I'll look into this and see if I can find a solution.

dapriett commented 5 years ago

Sorry, I haven't had any time to look at this - but if someone can submit a pull request for a fix, I'll get it merged in.

Maybe try the dev version of nativescript 6 since that officially supports AndroidX

npm install -g nativescript@next
npm install tns-core-modules@androidx --save-exact
tns platform add android@androidx
npm install tns-platform-declarations@androidx --save-exact
18clans commented 5 years ago

@kaspervm I found the solution.

Make sure you add this in the AndroidManifest.xml inside <application> tag.

<uses-library android:name="org.apache.http.legacy" android:required="false"/>

AndroidManifest.xml <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="PACKAGE" android:versionCode="10000" android:versionName="1.0">

<supports-screens
    android:smallScreens="true"
    android:normalScreens="true"
    android:largeScreens="true"
    android:xlargeScreens="true"/>

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.INTERNET"/>

<application
    android:name="com.tns.NativeScriptApplication"
    android:allowBackup="true"
    android:icon="@drawable/icon"
    android:label="@string/app_name"
    android:theme="@style/AppTheme">
       <uses-library android:name="org.apache.http.legacy" android:required="false"/>

    <activity
        android:name="com.tns.NativeScriptActivity"
        android:label="@string/title_activity_kimera"
        android:configChanges="keyboard|keyboardHidden|orientation|screenSize|smallestScreenSize|screenLayout|locale|uiMode"
        android:theme="@style/LaunchScreenTheme">

        <meta-data android:name="SET_THEME_ON_LAUNCH" android:resource="@style/AppTheme" />

        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name="com.tns.ErrorReportActivity"/>
    <meta-data
        android:name="com.google.android.geo.API_KEY"
        android:value="@string/nativescript_google_maps_api_key" />

</application>

18clans commented 5 years ago

The issue why we're having this issue today is because Google released a new version of Google Play Services (breaking change).

You will have to migrate your plugins in NativeScript to support AndroidX.

The temporary fix is to use Google Play Service version 15.0.0.

Create a before-plugins.gradle next to app.gradle inside App_Resources > Android and use the code below.

before-plugins.gradle

android {  
  project.ext {
      googlePlayServicesVersion = "15.0.0"
  }
} 

Make sure you add this in the AndroidManifest.xml inside <application> tag.

AndroidManifest.xml

<application>
...
...
<uses-library android:name="org.apache.http.legacy" android:required="false"/>
...
...
</application>

I had to delete my platforms folder first before doing a tns build/run android --bundle again. Try this out and let me know if this fixes your problem.

@dapriett I don't know if what I have is the solution but a workaround if you haven't upgraded to the latest version of {N}.

ideencorporation commented 5 years ago

Hi @18clans . This error appeared when creating a blank project.

  1. tns create test

  2. tns plugin add nativescript-google-maps-sdk

  3. gradle: android { project.ext { googlePlayServicesVersion = "15.0.0" } defaultConfig { minSdkVersion 17 generatedDensities = [] } aaptOptions { additionalParameters "--no-version-vectors" }

  4. Manifest: ...

    <application android:name="com.tns.NativeScriptApplication" android:allowBackup="true"x android:icon="@drawable/icon" android:label="@string/app_name" android:theme="@style/AppTheme">

< uses-library android:name="org.apache.http.legacy" android:required="false" />

...

  1. ERROR:
    
    Error:
        Attribute application@appComponentFactory value=(android.support.v4.app.CoreComponentFactory) from [com.android.support:support-compat:28.0.0] AndroidManifest.xml:22:18-91
        is also present at [androidx.core:core:1.0.0] AndroidManifest.xml:22:18-86 value=(androidx.core.app.CoreComponentFactory).
        Suggestion: add 'tools:replace="android:appComponentFactory"' to <application> element at AndroidManifest.xml:17:2-39:16 to override.

FAILURE: Build failed with an exception.

BUILD FAILED in 15s Unable to apply changes on device: LCL0218813003638. Error is: Command gradlew.bat failed with exit code 1.

18clans commented 5 years ago

@ideencorporation Which template did you use? Angular, Vue, Plain JS or Plain TypeScript? Can you run tns info and copy the output? Also, can you show me your package.json?

Did you run npm i before doing tns run android --bundle?

ideencorporation commented 5 years ago

I deleted nodejs and NS. I did a full reinstall.

  1. Template: helloworld (App complete in: https://we.tl/t-9SZYb5EB1z --id google maps is fake)

  2. JS Plain

  3. TNS INFO:

    √ Getting NativeScript components versions information...
    √ Component nativescript has 5.4.2 version and is up to date.
    √ Component tns-core-modules has 5.4.2 version and is up to date.
    √ Component tns-android has 5.4.0 version and is up to date.
    √ Component tns-ios has 5.4.2 version and is up to date.
  4. package.json:

    
    {
    "nativescript": {
    "id": "org.nativescript.test",
    "tns-android": {
      "version": "5.4.0"
    },
    "tns-ios": {
      "version": "5.4.2"
    }
    },
    "description": "NativeScript Application",
    "license": "SEE LICENSE IN <your-license-filename>",
    "repository": "<fill-your-repository-here>",
    "dependencies": {
    "nativescript-google-maps-sdk": "^2.7.0",
    "nativescript-theme-core": "~1.0.4",
    "tns-core-modules": "~5.4.0"
    },
    "devDependencies": {
    "nativescript-dev-webpack": "~0.24.0"
    },
    "gitHead": "8c1a4866a66daab09bf5ef8e5a96472687192373",
    "readme": "NativeScript Application"
    }
ideencorporation commented 5 years ago

npm install


npm WARN ts-loader@5.4.5 requires a peer of typescript@* but none is installed. You
must install peer dependencies yourself.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.9 (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.9: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})

audited 9270 packages in 8.493s found 1 moderate severity vulnerability run npm audit fix to fix them, or npm audit for details

>tns run android --bundle

D:\NS\test\platforms\android\app\src\main\AndroidManifest.xml:22:18-91 Error: Attribute application@appComponentFactory value=(android.support.v4.app.CoreComponentFactory) from [com.android.support:support-compat:28.0.0] AndroidManifest.xml:22:18-91 is also present at [androidx.core:core:1.0.0] AndroidManifest.xml:22:18-86 value=(androidx.core.app.CoreComponentFactory). Suggestion: add 'tools:replace="android:appComponentFactory"' to element at AndroidManifest.xml:17:2-42:16 to override.

FAILURE: Build failed with an exception.

BUILD FAILED in 3s Unable to apply changes on device: emulator-5554. Error is: Command gradlew.bat failed with exit code 1.

18clans commented 5 years ago

@ideencorporation Remove this from your app.gradle.

project.ext {
googlePlayServicesVersion = "15.0.0"
}

Create a new file called before-plugins.gradle in the same location as app.gradle. Copy this code into before-plugins.gradle.

android {  
  project.ext {
      googlePlayServicesVersion = "15.0.0"
  }
} 

Delete your platforms folder and try to run again.