Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

multiple_maps - Android: Use pure Android X and latest Google Maps SDK #2942

Open
wants to merge 1 commit into
base: multiple_maps
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@
<preference name="BackgroundColor" value="0"/>

<!-- for this plugin -->
<preference name="android-minSdkVersion" value="19"/>
<preference name="android-minSdkVersion" value="21"/>
</config-file>

<config-file target="res/xml/config.xml" parent="/*">
Expand Down Expand Up @@ -302,8 +302,6 @@
<!-- localized messages for Vietnamese -->
<resource-file src="src/android/res/values-vi/pgm_strings.xml" target="res/values-vi/pgm_strings.xml"/>

<dependency id="cordova-androidx-build" />

</platform>

<!-- ios -->
Expand Down
149 changes: 31 additions & 118 deletions src/android/frameworks/pgm-custom.gradle
Original file line number Diff line number Diff line change
@@ -1,87 +1,17 @@
def getConvertListe(useAndroidX) {
def list = [
["com.google.android.gms.maps.model", "com.google.android.libraries.maps.model"],
["com.google.android.gms.maps", "com.google.android.libraries.maps"]
]

if (!useAndroidX) {
def tmp;
def listN = list.size()
for (int i = 0; i < listN; i++) {
tmp = list[i][0]
list[i][0] = list[i][1]
list[i][1] = tmp
}
}
return list
}


def searchFileInParents(target) {
def searchPath = target

for (int i = 0; i < 8; i++) {
println(searchPath)
def targetFile = file(searchPath)

if(!targetFile.canRead()) {
searchPath = '../' + searchPath;
} else {
return targetFile;
}
}
return null;
}

def replacePackages(file, cvtList, useAndroidX) {
def filePath = file.toPath()
def lines = java.nio.file.Files.readAllLines(filePath)
def linesN = lines.size()
def listN = cvtList.size()
def anyChanges = false
for (int i = 0; i < linesN; i++) {
def line = lines.get(i)
def needReplace = false;
if (useAndroidX && line.contains('android.')) {
needReplace = true
} else if (!useAndroidX && line.contains('android')) {
needReplace = true
}
if (needReplace) {
for (int j = 0; j < listN; j++) {
if (line.contains(cvtList[j][0])) {
anyChanges = true
line = line.replaceAll(cvtList[j][0], cvtList[j][1])
}
}
lines.set(i, line)
}
}

if (anyChanges) {
println(" [changed] " + file)
def fileWriter = new FileWriter(file)
def output = new BufferedWriter(fileWriter)
for (int i = 0; i < linesN; i++) {
output.writeLine(lines.get(i))
}
output.flush()
output.close()
fileWriter.close()
}

}
def replaceFiles(matchingPattern, cvtList, useAndroidX) {

PatternFilterable patternSet = new PatternSet();
patternSet.include(matchingPattern);

def matchedFile = project.files(project.getProjectDir().getParentFile().toPath()).getAsFileTree().matching(patternSet)
matchedFile.each { file ->
if (!java.nio.file.Files.isReadable(file.toPath())) {
return
}

replacePackages(file, cvtList, useAndroidX)
}
return null;
}

android {
Expand All @@ -101,82 +31,65 @@ android {

// parse xml file
def widget = new XmlParser().parse(configXmlFile)

if (widget.preference == null) {
throw new GradleException("widget is null.")
}

if (widget.preference.size() == 0) {
throw new GradleException("Please add '<preference name=\"GOOGLE_MAPS_ANDROID_API_KEY\" />' to the config.xml file.")
}

Properties props = new Properties()
def isKeyFound = 0

props.setProperty("GOOGLE_MAPS_PLAY_SERVICES_LOCATION_VERSION", "16.0.0");
props.setProperty("GOOGLE_MAPS_ANDROID_SUPPORT_V4_VERSION", "27.1.1");
props.setProperty("GOOGLE_MAPS_PLAY_SERVICES_VERSION", "16.1.0");

// Set default versions for play-services-maps and play-services-location
//
// Google Maps SDK for Android: com.google.android.gms:play-services-maps
// Version from 25.06.2024
props.setProperty("GOOGLE_MAPS_PLAY_SERVICES_VERSION", "19.0.0");
// Location Services for Android: com.google.android.gms:play-services-location
// Version from 29.05.2024
props.setProperty("GOOGLE_MAPS_PLAY_SERVICES_LOCATION_VERSION", "21.3.0");

widget.preference.each { pref ->
def name = pref.attributes().name
def value = pref.attributes().value
println("name = " + name);

if (name == "GOOGLE_MAPS_ANDROID_API_KEY") {
isKeyFound = 1
props.setProperty(name, value)
}
if (name == "GOOGLE_MAPS_PLAY_SERVICES_LOCATION_VERSION"||
name == "GOOGLE_MAPS_PLAY_SERVICES_VERSION" ||
name == "GOOGLE_MAPS_ANDROID_SUPPORT_V4_VERSION") {

if (name == "GOOGLE_MAPS_PLAY_SERVICES_VERSION" ||
name == "GOOGLE_MAPS_PLAY_SERVICES_LOCATION_VERSION") {
props.setProperty(name, value)
}
}


if (isKeyFound == 0) {
throw new GradleException("Please add '<preference name=\"GOOGLE_MAPS_ANDROID_API_KEY\" />' to the config.xml file.")
}

def hasUseAndroidX = project.ext.has('android.useAndroidX')
def hasEnableJetifier = project.ext.has('android.enableJetifier')
def useAndroidX = hasUseAndroidX && hasEnableJetifier &&
'true' == project.ext.get('android.useAndroidX') &&
'true' == project.ext.get('android.enableJetifier')

//-----------------------------------------------
// Replace the source code of this plugin
//-----------------------------------------------
def cvtList = getConvertListe(useAndroidX)
def hasUseAndroidX = project.ext.has('android.useAndroidX') && (project.ext.get('android.useAndroidX') == 'true')
def hasEnableJetifier = project.ext.has('android.enableJetifier') && (project.ext.get('android.enableJetifier') == 'true')
def useAndroidX = hasUseAndroidX && hasEnableJetifier

replaceFiles("**/plugin/google/maps/*.java", cvtList, useAndroidX)

if (useAndroidX) {
//----------
// maps SDK
//----------
if (!useAndroidX) {
throw new GradleException("Android X must be used to use this plugin.")
}

dependencies {
implementation 'com.google.android.libraries.maps:maps:3.1.0-beta'
implementation 'com.android.support:multidex:1.0.3'
}
def PLAY_SERVICES_MAPS_VERSION = props.getProperty("GOOGLE_MAPS_PLAY_SERVICES_VERSION")
def PLAY_SERVICES_LOCATION_VERSION = props.getProperty("GOOGLE_MAPS_PLAY_SERVICES_LOCATION_VERSION")

defaultConfig {
multiDexEnabled true
}
println("---->GOOGLE_MAPS_PLAY_SERVICES_VERSION = ${PLAY_SERVICES_MAPS_VERSION}")
println("---->GOOGLE_MAPS_PLAY_SERVICES_LOCATION_VERSION = ${PLAY_SERVICES_LOCATION_VERSION}")

} else {
def PLAY_SERVICES_VERSION = props.getProperty("GOOGLE_MAPS_PLAY_SERVICES_VERSION")
def PLAY_SERVICES_LOCATION_VERSION = props.getProperty("GOOGLE_MAPS_PLAY_SERVICES_LOCATION_VERSION")
def ANDROID_SUPPORT_V4_VERSION = props.getProperty("GOOGLE_MAPS_ANDROID_SUPPORT_V4_VERSION")
println("---->GOOGLE_MAPS_PLAY_SERVICES_VERSION = ${PLAY_SERVICES_VERSION}")
println("---->GOOGLE_MAPS_PLAY_SERVICES_LOCATION_VERSION = ${PLAY_SERVICES_LOCATION_VERSION}")
println("---->GOOGLE_MAPS_ANDROID_SUPPORT_V4_VERSION = ${ANDROID_SUPPORT_V4_VERSION}")
dependencies {
implementation "com.google.android.gms:play-services-maps:${PLAY_SERVICES_VERSION}"
implementation "com.google.android.gms:play-services-location:${PLAY_SERVICES_LOCATION_VERSION}"
implementation "com.android.support:support-core-utils:${ANDROID_SUPPORT_V4_VERSION}"
}
dependencies {
implementation "com.google.android.gms:play-services-maps:${PLAY_SERVICES_MAPS_VERSION}"
implementation "com.google.android.gms:play-services-location:${PLAY_SERVICES_LOCATION_VERSION}"
}


buildTypes {
debug {
manifestPlaceholders.GOOGLE_MAPS_ANDROID_API_KEY = props.getProperty("GOOGLE_MAPS_ANDROID_API_KEY")
Expand Down
5 changes: 4 additions & 1 deletion src/android/frameworks/tbxml-android.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ repositories {
maven { url 'https://maven.google.com' }
mavenCentral()
jcenter()

def libsDirPath = System.getProperty("user.dir")
flatDir{

// Causes Warning: Using flatDir should be avoided because it doesn't support any meta-data formats.
flatDir {
dirs 'src/main/libs', 'libs', "${libsDirPath}/libs"
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/android/plugin/google/maps/BitmapCache.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package plugin.google.maps;

import android.graphics.Bitmap;
import android.support.v4.util.LruCache;
import androidx.collection.LruCache;

public class BitmapCache extends LruCache<String, Bitmap> {

Expand Down
2 changes: 1 addition & 1 deletion src/android/plugin/google/maps/ObjectCache.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package plugin.google.maps;

import android.support.v4.util.LruCache;
import androidx.collection.LruCache;

import java.util.HashSet;

Expand Down
4 changes: 2 additions & 2 deletions src/android/plugin/google/maps/PluginLocationService.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
import android.os.Build;
import android.os.Bundle;
import android.os.Looper;
import android.support.annotation.NonNull;
import android.support.v4.content.PermissionChecker;
import androidx.annotation.NonNull;
import androidx.core.content.PermissionChecker;
import android.util.Log;

import com.google.android.gms.common.ConnectionResult;
Expand Down
4 changes: 2 additions & 2 deletions src/android/plugin/google/maps/PluginMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.support.annotation.NonNull;
import android.support.v4.content.PermissionChecker;
import androidx.annotation.NonNull;
import androidx.core.content.PermissionChecker;
import android.util.Base64;
import android.util.Log;
import android.view.Gravity;
Expand Down