Reputation: 46
I included sdk file from https://developer.here.com by this location my_plugin/src/platforms/android/HERE-sdk.aar
. In java code I can use it like this:
package com.here.android.tutorial;
...
import com.here.android.mpa.mapping.MapFragment;
...
private MapFragment mapFragment = null;
private void initialize() {
mapFragment = (MapFragment) getFragmentManager().findFragmentById(R.id.mapfragment);
...
I tried this:
// my-plugin.android.ts
import { Common } from './my-plugin.common';
declare var com: any;
export class MyPlugin extends Common {
public mapFragment: any;
constructor() {
super();
this.mapFragment = new com.here.android.mpa.mapping.MapFragment()
}
}
But it shows error: TypeError: Cannot read property 'android' of undefined
How to properly include .aar
library file and use MapFragment in Nativescript(JS) code?
Upvotes: 0
Views: 440
Reputation: 33
In addition to the other answers, I had to remove/add the platform
tns platform remove android
tns platform add android
tns run android
Upvotes: 1
Reputation: 46
Problem solved! Here is solution:
To use native lib with Nativescript plugin, it's enough to put lib to MY_PLUGIN/src/platforms/android
directory. No need to edit include.gradle
file! Nativescript will find library itself. So the directory structure should look like this:
To make Here SDK works open AndroidManifest.xml
, add permissions and credentials. So it will look like this:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<application android:hardwareAccelerated="true">
<meta-data android:name="com.here.android.maps.appid"
android:value="{ YOUR_APPID }"/>
<meta-data android:name="com.here.android.maps.apptoken"
android:value="{ YOUR_APPTOKEN }"/>
</application>
Upvotes: 1
Reputation:
Check your gradle properties to see if you included the Here-sdk like below:
dependencies {
implementation fileTree(dir: 'libs', include: ['HERE-sdk.aar'])
implementation 'com.android.support:appcompat-v7:28.0.0-rc02'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
compile 'com.google.code.gson:gson:2.8.0'
}
You can also try the following
Upvotes: 0
Reputation: 21908
You have to add the aar file as dependency into include.gradle
compile(name: 'HERE-sdk', ext: 'aar')
Upvotes: 0