Skip to content

Commit ec53cc1

Browse files
authored
feat!: upgrade Android Driver SDK to version 7.0.0 (#75)
1 parent 0bd12f1 commit ec53cc1

File tree

15 files changed

+272
-79
lines changed

15 files changed

+272
-79
lines changed

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ This is the beta release of the Google Driver SDK package for React Native. It i
1515

1616
| | Android | iOS |
1717
| ------------------------------- | ------- | --------- |
18-
| **Minimum mobile OS supported** | SDK 24+ | iOS 16.0+ |
18+
| **Minimum mobile OS supported** | SDK 26+ | iOS 16.0+ |
19+
| **Compile/Target SDK** | SDK 36+ | - |
1920

2021
* A React Native project
2122
* A Google Cloud project
@@ -100,16 +101,18 @@ dependencies {
100101

101102
#### Minimum SDK Requirements for Android
102103

103-
The `minSdkVersion` for your Android project must be set to 24 or higher in `android/app/build.gradle`:
104+
The `minSdkVersion` for your Android project must be set to 26 or higher in `android/app/build.gradle`:
104105

105106
```groovy
106107
android {
107108
defaultConfig {
108-
minSdkVersion 24
109+
minSdkVersion 26
109110
}
110111
}
111112
```
112113

114+
The `compileSdkVersion` and `targetSdkVersion` should be set to 36 or higher.
115+
113116
#### Set Google Maps API Key
114117

115118
To securely store your API key, it is recommended to use the [Google Maps Secrets Gradle Plugin](https://developers.google.com/maps/documentation/android-sdk/secrets-gradle-plugin). This plugin helps manage API keys without exposing them in your app's source code.

android/build.gradle

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,16 @@ if (isNewArchitectureEnabled()) {
4040
android {
4141
namespace "com.google.android.react.driversdk"
4242

43-
compileSdkVersion 35
43+
compileSdkVersion 36
4444

4545
compileOptions {
4646
sourceCompatibility JavaVersion.VERSION_1_8
4747
targetCompatibility JavaVersion.VERSION_1_8
4848
}
4949

5050
defaultConfig {
51-
minSdkVersion 23
52-
targetSdkVersion 34
51+
minSdkVersion 26
52+
targetSdkVersion 36
5353
versionCode 1
5454
// get version name from package.json version
5555
versionName "1.0"
@@ -85,7 +85,7 @@ repositories {
8585
}
8686

8787
dependencies {
88-
implementation 'com.google.android.libraries.mapsplatform.transportation:transportation-driver:6.2.0'
88+
implementation 'com.google.android.libraries.mapsplatform.transportation:transportation-driver:7.0.0'
8989
implementation 'com.facebook.react:react-native:+'
9090
implementation 'com.android.support:multidex:1.0.3'
9191
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'

android/src/main/java/com/google/android/react/driversdk/lmfs/DeliveryDriverModule.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ public void setLocationReportingInterval(int interval, Promise promise) {
137137
return;
138138
}
139139

140-
vehicleReporter.setLocationReportingInterval(new Long(interval), TimeUnit.SECONDS);
140+
vehicleReporter.setLocationReportingInterval(Long.valueOf(interval), TimeUnit.SECONDS);
141141
} catch (Exception e) {
142142
promise.reject(e.toString(), e.getMessage(), e);
143143
}

android/src/main/java/com/google/android/react/driversdk/odrd/RidesharingModule.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ public void setLocationReportingInterval(int interval, Promise promise) {
161161
return;
162162
}
163163

164-
vehicleReporter.setLocationReportingInterval(new Long(interval), TimeUnit.SECONDS);
164+
vehicleReporter.setLocationReportingInterval(Long.valueOf(interval), TimeUnit.SECONDS);
165165
} catch (Exception e) {
166166
promise.reject(e.toString(), e.getMessage(), e);
167167
}

example/.env.sample

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,9 @@ IOS_HOST=localhost
3434
LMFS_PORT=8091
3535
ODRD_PORT=8092
3636

37+
# Optional: Set vehicle IDs for the example apps (can also be set in the app UI or code)
38+
# LMFS_VEHICLE_ID=your_lmfs_vehicle_id
39+
# ODRD_VEHICLE_ID=your_odrd_vehicle_id
40+
3741
# This is typically `~/.config/gcloud` on MacOS and Linux, or `%APPDATA%\gcloud` on Windows. See ./tools/backend/README.md for more details.
3842
GCLOUD_CONFIG_DIR=~/.config/gcloud

example/LMFS/README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,13 @@ This is a sample application that show cases developers how to integrate with th
88

99
1. This library depends on the LMFS backend available in https://github.com/googlemaps/last-mile-fleet-solution-samples/tree/main/backend. This package provides docker-compose files to run the backend services at `/example/tools/backend` folder. For more information, please refer to the [README](../tools/backend/README.md) file in the tools/backend folder of the example app.
1010
2. Once the backend is setup, create a delivery vehicle and keep the vehicleId handy. In order to make it easier to create vehicles with tasks, you can use the `/upload-delivery-config.html` endpoint on the backend. [example json](https://raw.githubusercontent.com/googlemaps/last-mile-fleet-solution-samples/main/backend/src/test/resources/test.json)
11-
3. Go to the [App.tsx](/example/LMFS/src/App.tsx) file and update the VEHICLE_ID from the endpoint response.
11+
3. Configure the VEHICLE_ID using one of the following methods:
12+
- **Option 1: .env file (Recommended)** - Add the vehicle ID to your `.env` file in the `example` folder:
13+
```
14+
LMFS_VEHICLE_ID=your_vehicle_id
15+
```
16+
- **Option 2: Direct Input** - When you start the app, you can enter the vehicle ID directly in the "VEHICLE_ID Not Configured" screen.
17+
- **Option 3: Code Update** - Go to the [App.tsx](/example/LMFS/src/App.tsx) file and update the VEHICLE_ID_DEFAULT constant with your vehicle ID.
1218
1319
## Setup
1420

example/LMFS/android/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def enableDesugaring = true
2020
buildscript {
2121
ext {
2222
buildToolsVersion = "36.0.0"
23-
minSdkVersion = 34
23+
minSdkVersion = 26
2424
compileSdkVersion = 36
2525
targetSdkVersion = 36
2626
ndkVersion = "27.1.12297006"

example/LMFS/babel.config.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,14 @@ module.exports = getConfig(
2727
{
2828
envName: 'APP_ENV',
2929
path: '../.env',
30-
allowlist: ['PROJECT_ID', 'ANDROID_HOST', 'IOS_HOST', 'LMFS_PORT'],
31-
allowUndefined: false,
30+
allowlist: [
31+
'PROJECT_ID',
32+
'ANDROID_HOST',
33+
'IOS_HOST',
34+
'LMFS_PORT',
35+
'LMFS_VEHICLE_ID',
36+
],
37+
allowUndefined: true,
3238
verbose: false,
3339
},
3440
],

example/LMFS/env.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@ declare module '@env' {
1919
export const ANDROID_HOST: string;
2020
export const IOS_HOST: string;
2121
export const LMFS_PORT: number;
22+
export const LMFS_VEHICLE_ID: string;
2223
}

example/LMFS/src/App.tsx

Lines changed: 111 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { useCallback, useEffect, useMemo, useState } from 'react';
1919
import {
2020
StyleSheet,
2121
Text,
22+
TextInput,
2223
View,
2324
Platform,
2425
Modal,
@@ -46,6 +47,7 @@ import {
4647
ANDROID_HOST,
4748
IOS_HOST,
4849
LMFS_PORT,
50+
LMFS_VEHICLE_ID,
4951
} from '@env';
5052
import usePermissions from './checkPermissions';
5153

@@ -56,7 +58,12 @@ const BASE_URL =
5658
: `http://${IOS_HOST}:${LMFS_PORT}`;
5759

5860
// Update this vehicle id from the response from the /upload-delivery-config.html backend endpoint.
59-
const VEHICLE_ID = ''; // ADD_VEHICLE_ID_HERE
61+
// Can also be set via LMFS_VEHICLE_ID in .env file or as environment variable:
62+
// See README.md for configuration options.
63+
const VEHICLE_ID_DEFAULT = LMFS_VEHICLE_ID || ''; // ADD_VEHICLE_ID_HERE
64+
65+
// New location reporting interval in seconds that is applied via menu action.
66+
const NEW_LOCATION_REPORTING_INTERVAL_SECONDS = 20;
6067

6168
const termsAndConditionsDialogOptions: TermsAndConditionsDialogOptions = {
6269
title: 'RN LMFS Sample',
@@ -78,6 +85,9 @@ function LMFSSampleApp() {
7885
useState(false);
7986
const [authToken, setAuthToken] = useState<string | null>(null);
8087
const [driverSdkVersion, setDriverSdkVersion] = useState<string>('');
88+
const [vehicleId, setVehicleId] = useState<string>(VEHICLE_ID_DEFAULT);
89+
const [tempVehicleId, setTempVehicleId] =
90+
useState<string>(VEHICLE_ID_DEFAULT);
8191

8292
const clearInstance = useCallback(async () => {
8393
await deliveryDriverApi.clearInstance();
@@ -153,7 +163,33 @@ function LMFSSampleApp() {
153163
[onArrival, onNavigationReady, onNavigationInitError, onRouteStatusResult]
154164
);
155165

166+
const fetchAuthToken = useCallback(async () => {
167+
if (!vehicleId) {
168+
console.log('Vehicle ID not set, skipping auth token fetch');
169+
return;
170+
}
171+
try {
172+
console.log('Fetching auth token...');
173+
const tokenUrl = BASE_URL + '/token/delivery_driver/' + vehicleId;
174+
const response = await fetch(tokenUrl);
175+
const { token } = await response.json();
176+
console.log('Got token:', token);
177+
178+
setAuthToken(token);
179+
} catch (error) {
180+
console.log(
181+
'There has been a problem connecting to the provider, please make sure it is running. ',
182+
error
183+
);
184+
}
185+
}, [vehicleId]);
186+
156187
useEffect(() => {
188+
if (!vehicleId) {
189+
console.log('Vehicle ID not set, skipping initialization');
190+
return;
191+
}
192+
157193
console.log('Init LMFS Example app');
158194
removeListeners(navigationCallbacks);
159195
addListeners(navigationCallbacks);
@@ -167,31 +203,21 @@ function LMFSSampleApp() {
167203
removeListeners(navigationCallbacks);
168204
clearInstance();
169205
};
170-
}, [clearInstance, navigationCallbacks, addListeners, removeListeners]);
171-
172-
const fetchAuthToken = async () => {
173-
try {
174-
console.log('Fetching auth token...');
175-
const tokenUrl = BASE_URL + '/token/delivery_driver/' + VEHICLE_ID;
176-
const response = await fetch(tokenUrl);
177-
const { token } = await response.json();
178-
console.log('Got token:', token);
179-
180-
setAuthToken(token);
181-
} catch (error) {
182-
console.log(
183-
'There has been a problem connecting to the provider, please make sure it is running. ',
184-
error
185-
);
186-
}
187-
};
206+
}, [
207+
clearInstance,
208+
navigationCallbacks,
209+
addListeners,
210+
removeListeners,
211+
vehicleId,
212+
fetchAuthToken,
213+
]);
188214

189215
const createInstance = async () => {
190216
try {
191217
console.log('Creating LMFS instance');
192218
await deliveryDriverApi.initialize(
193219
PROVIDER_ID,
194-
VEHICLE_ID,
220+
vehicleId,
195221
_tokenContext => {
196222
console.log('onGetToken call, return token: ', authToken);
197223
// Check if the token is expired, in such case request a new one.
@@ -237,11 +263,14 @@ function LMFSSampleApp() {
237263
}
238264
};
239265

240-
const setUpdateInterval = async () => {
266+
const setLocationReportingInterval = async () => {
241267
try {
242268
await deliveryDriverApi
243269
.getDeliveryVehicleReporter()
244-
.setLocationReportingInterval(20);
270+
.setLocationReportingInterval(NEW_LOCATION_REPORTING_INTERVAL_SECONDS);
271+
console.log(
272+
`Location reporting interval set to ${NEW_LOCATION_REPORTING_INTERVAL_SECONDS} seconds`
273+
);
245274
} catch (e) {
246275
console.error(e);
247276
}
@@ -313,19 +342,54 @@ function LMFSSampleApp() {
313342
const controlsButtonColor = '#d32f2f';
314343
const controlsButtonColorPressed = '#a12020';
315344

316-
if (!VEHICLE_ID) {
345+
const handleSetVehicleId = () => {
346+
if (tempVehicleId.trim()) {
347+
setVehicleId(tempVehicleId.trim());
348+
}
349+
};
350+
351+
if (!vehicleId) {
317352
return (
318353
<SafeAreaView style={styles.container} edges={['top', 'bottom']}>
319354
<View style={styles.alertContainer}>
320355
<Text style={styles.alertTitle}>VEHICLE_ID Not Configured</Text>
321356
<Text style={styles.alertMessage}>
322-
Please set the VEHICLE_ID in App.tsx before running the app.
357+
Please set the VEHICLE_ID to continue.
323358
</Text>
324359
<Text style={styles.alertInstructions}>
325-
To configure:
326-
{'\n'}1. Follow the setup instructions in the README
327-
{'\n'}2. Create a delivery vehicle using the backend
328-
{'\n'}3. Update VEHICLE_ID in example/LMFS/src/App.tsx
360+
You can configure the vehicle ID in one of three ways:
361+
{'\n'}
362+
{'\n'}1. Add it to your .env file:
363+
{'\n'} LMFS_VEHICLE_ID=your_vehicle_id
364+
{'\n'}
365+
{'\n'}2. Enter it directly below:
366+
</Text>
367+
<View style={styles.inputContainer}>
368+
<TextInput
369+
style={styles.input}
370+
placeholder="Enter Vehicle ID"
371+
placeholderTextColor="#999"
372+
value={tempVehicleId}
373+
onChangeText={setTempVehicleId}
374+
autoCapitalize="none"
375+
autoCorrect={false}
376+
/>
377+
<View style={styles.buttonWrapper}>
378+
<ActionButton
379+
title="Set Vehicle ID"
380+
onPress={handleSetVehicleId}
381+
backgroundColor={buttonBackgroundColor}
382+
pressedBackgroundColor={buttonBackgroundColorPressed}
383+
/>
384+
</View>
385+
</View>
386+
<Text style={styles.alertInstructions}>
387+
{'\n'}3. Update VEHICLE_ID_DEFAULT in example/LMFS/src/App.tsx
388+
{'\n'}
389+
{'\n'}To create a vehicle:
390+
{'\n'}• Follow the setup instructions in the README
391+
{'\n'}• Create a delivery vehicle using the backend
392+
{'\n'}• Use the vehicle ID from the response
329393
{'\n'}
330394
{'\n'}See README.md for detailed instructions.
331395
</Text>
@@ -355,7 +419,7 @@ function LMFSSampleApp() {
355419
numberOfLines={1}
356420
ellipsizeMode="tail"
357421
>
358-
Vehicle ID: {VEHICLE_ID || 'Not set'}
422+
Vehicle ID: {vehicleId || 'Not set'}
359423
</Text>
360424
<Text
361425
style={styles.versionText}
@@ -402,8 +466,8 @@ function LMFSSampleApp() {
402466
</View>
403467
<View style={styles.buttonWrapper}>
404468
<ActionButton
405-
title="Update time interval"
406-
onPress={setUpdateInterval}
469+
title={`Set Location Reporting Interval to ${NEW_LOCATION_REPORTING_INTERVAL_SECONDS}s`}
470+
onPress={setLocationReportingInterval}
407471
backgroundColor={buttonBackgroundColor}
408472
pressedBackgroundColor={buttonBackgroundColorPressed}
409473
/>
@@ -642,6 +706,22 @@ const styles = StyleSheet.create({
642706
color: '#0b1a2a',
643707
fontWeight: '600',
644708
},
709+
inputContainer: {
710+
marginVertical: 16,
711+
width: '100%',
712+
maxWidth: 400,
713+
},
714+
input: {
715+
backgroundColor: '#ffffff',
716+
borderWidth: 1,
717+
borderColor: '#ccc',
718+
borderRadius: 8,
719+
paddingVertical: 12,
720+
paddingHorizontal: 16,
721+
fontSize: 16,
722+
color: '#0b1a2a',
723+
marginBottom: 12,
724+
},
645725
});
646726

647727
export default App;

0 commit comments

Comments
 (0)