Skip to content

Commit

Permalink
Fix: Get example for android working
Browse files Browse the repository at this point in the history
  • Loading branch information
gciluffo committed Jan 27, 2022
1 parent af4f0a4 commit 8431b8e
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 3 deletions.
27 changes: 26 additions & 1 deletion example/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,44 @@
* @flow strict-local
*/

import React from 'react';
import React, {useState, useLayoutEffect} from 'react';
import {SafeAreaView, useColorScheme} from 'react-native';
import {Colors} from 'react-native/Libraries/NewAppScreen';
import NavigationComponent from './NavigationComponent';
import {PermissionsAndroid} from 'react-native';

const App = () => {
const [locationPermissionGranted, setLocationPermissionGranted] =
useState(false);

const isDarkMode = useColorScheme() === 'dark';

const backgroundStyle = {
backgroundColor: isDarkMode ? Colors.darker : Colors.lighter,
flex: 1,
};

useLayoutEffect(async () => {
async function requestLocationPermission() {
try {
const granted = await PermissionsAndroid.request(
PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,
{
title: 'Example App',
message: 'Example App access to your location ',
},
);
if (granted) {
setLocationPermissionGranted(true);
}
} catch (err) {
console.warn(err);
}
}

requestLocationPermission();
}, []);

return (
<SafeAreaView style={backgroundStyle}>
<NavigationComponent
Expand Down
2 changes: 2 additions & 0 deletions example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,8 @@ dependencies {
} else {
implementation jscFlavor
}

implementation project(':mapboxnavigation')
}

// Run this once to be able to run the application with BUCK
Expand Down
5 changes: 5 additions & 0 deletions example/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
package="com.basicapp">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

<application
android:name=".MainApplication"
Expand All @@ -21,5 +24,7 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data android:name="MAPBOX_ACCESS_TOKEN"
android:value="pk.eyJ1Ijoiam9yZ2VxdWV2ZWRveCIsImEiOiJja3FiOXltNHowNGdyMnFwM3R4N3ZiMDBnIn0.Hv8IGOAsBT42OfStxBgxag" />
</application>
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.facebook.soloader.SoLoader;
import java.lang.reflect.InvocationTargetException;
import java.util.List;
import com.homee.mapboxnavigation.MapboxNavigationPackage;

public class MainApplication extends Application implements ReactApplication {

Expand All @@ -25,7 +26,7 @@ protected List<ReactPackage> getPackages() {
@SuppressWarnings("UnnecessaryLocalVariable")
List<ReactPackage> packages = new PackageList(this).getPackages();
// Packages that cannot be autolinked yet can be added manually here, for example:
// packages.add(new MyReactNativePackage());
packages.add(new MapboxNavigationPackage());
return packages;
}

Expand Down
13 changes: 13 additions & 0 deletions example/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,18 @@ allprojects {
}
google()
maven { url 'https://www.jitpack.io' }
maven {
url 'https://api.mapbox.com/downloads/v2/releases/maven'
authentication {
basic(BasicAuthentication)
}
credentials {
// Do not change the username below.
// This should always be `mapbox` (not your username).
username = "mapbox"
// Use the secret token you stored in gradle.properties as the password
password = project.properties['MAPBOX_DOWNLOADS_TOKEN'] ?: ""
}
}
}
}
7 changes: 7 additions & 0 deletions example/android/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,10 @@ android.enableJetifier=true

# Version of flipper SDK to use with React Native
FLIPPER_VERSION=0.99.0

MAPBOX_DOWNLOADS_TOKEN= sk.eyJ1Ijoiam9yZ2VxdWV2ZWRveCIsImEiOiJja29ib3oycWIyN2Z3MnZvbmc0eGttOTI0In0.Wsd8kBSIh6RkhivVUWm3cw

org.gradle.jvmargs=-Xmx4096m -XX:MaxPermSize=4096m -XX:+HeapDumpOnOutOfMemoryError
org.gradle.daemon=true
org.gradle.parallel=true
org.gradle.configureondemand=true.
2 changes: 1 addition & 1 deletion example/android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.9-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
3 changes: 3 additions & 0 deletions example/android/settings.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
rootProject.name = 'BasicApp'
apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings)
include ':app'

include ':mapboxnavigation'
project(':mapboxnavigation').projectDir = new File(rootProject.projectDir, '../../android')

0 comments on commit 8431b8e

Please sign in to comment.