diff --git a/android/build.gradle b/android/build.gradle index 8e2c769..91f6497 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -3,7 +3,7 @@ apply plugin: 'com.android.library' def DEFAULT_COMPILE_SDK_VERSION = 28 def DEFAULT_TARGET_SDK_VERSION = 28 def DEFAULT_SUPPORT_LIB_VERSION = "28.0.0" -def DEFAULT_MIN_SDK_VERSION = 16 +def DEFAULT_MIN_SDK_VERSION = 21 def safeExtGet(prop, fallback) { rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback @@ -14,6 +14,7 @@ android { compileSdkVersion safeExtGet('compileSdkVersion', DEFAULT_COMPILE_SDK_VERSION) defaultConfig { + minSdkVersion 21 minSdkVersion safeExtGet('minSdkVersion', DEFAULT_MIN_SDK_VERSION) targetSdkVersion safeExtGet('targetSdkVersion', DEFAULT_TARGET_SDK_VERSION) resValue "string", "places_api_key", (System.env.RNGP_ANDROID_API_KEY ? "$System.env.RNGP_ANDROID_API_KEY" : (rootProject.findProperty("RNGP_ANDROID_API_KEY") ?: "INSERT_KEY_HERE")) diff --git a/package.json b/package.json index 0e950c8..c317a1b 100644 --- a/package.json +++ b/package.json @@ -31,5 +31,11 @@ "react": ">=15.4.0 || ^16.0.0-alpha", "react-native": ">=0.40.0" }, - "devDependencies": {} + "devDependencies": {}, + "rnpm": { + "commands": { + "prelink": "node_modules/react-native-google-places/scripts/pre-link.sh", + "postlink": "node_modules/react-native-google-places/scripts/post-link.sh" + } + } } \ No newline at end of file diff --git a/scripts/post-link-ios.rb b/scripts/post-link-ios.rb new file mode 100755 index 0000000..49ea271 --- /dev/null +++ b/scripts/post-link-ios.rb @@ -0,0 +1,70 @@ +#!/usr/bin/env ruby + +require 'xcodeproj' +require 'tempfile' +require 'fileutils' + +Dir.chdir('ios') + +@podfile_path = Pathname.pwd + 'Podfile' +@pod_dep_arr = ['GooglePlaces', 'GoogleMaps', 'GooglePlacePicker'] +@pod_dep = @pod_dep_arr.map{|dep| " pod '#{dep}'\n"}.join("") + +@project_paths= Pathname.pwd.children.select { |pn| pn.extname == '.xcodeproj' } +raise 'No Xcode project found' unless @project_paths.length > 0 +raise 'Multiple Xcode projects found' unless @project_paths.length == 1 +project_path = @project_paths.first + +project = Xcodeproj::Project.open(project_path) +main_target = project.targets.first + +puts "Checking Podfile in iOS project #{@podfile_path}" + + +if File.exist? @podfile_path + puts 'Found an existing Podfile' + puts "Adding the following pod to Podfile\n#{@pod_dep}" + temp_file = Tempfile.new('Podfile_temp') + + File.readlines(@podfile_path).each do |line| + if line =~ /pod\s'GooglePlaces'/ + @pod_dep_arr.delete('GooglePlaces') + puts 'GooglePlaces pod is already added' + elsif line =~ /pod\s'GoogleMaps'/ + @pod_dep_arr.delete('GoogleMaps') + puts 'GoogleMaps pod is already added' + elsif line =~ /pod\s'GooglePlacePicker'/ + @pod_dep_arr.delete('GooglePlacePicker') + puts 'GooglePlacePicker pod is already added' + end + end + + begin + escaped_target_name = main_target.name.gsub(/'/, "\\\\\'") + File.readlines(@podfile_path).each do |line| + temp_file.puts(line) + @pod_dep_arr.each do |dep| + temp_file.puts(" pod '#{dep}'") if line =~ /target\s+'#{escaped_target_name}'\s+do/ + end + end + temp_file.close + FileUtils.mv(temp_file.path, @podfile_path) + ensure + temp_file.delete + end +else + puts 'Adding Podfile to iOS project' + podfile = '' + + podfile << "# Uncomment the next line to define a global platform for your project\n# platform :ios, '9.0'\n" + podfile << "\ntarget '#{main_target.name.gsub(/'/, "\\\\\'")}' do\n" + podfile << @pod_dep + podfile << " inherit! :search_paths\n" + podfile << "end\n" + puts podfile + File.write(@podfile_path, podfile) +end + +puts 'Installing Pods' + +system 'pod install' diff --git a/scripts/post-link.sh b/scripts/post-link.sh new file mode 100755 index 0000000..10e66cd --- /dev/null +++ b/scripts/post-link.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +if [[ "$(uname)" == "Darwin" ]]; then + ruby $(dirname "$0")/post-link-ios.rb +fi + diff --git a/scripts/pre-link.sh b/scripts/pre-link.sh new file mode 100755 index 0000000..7cbad96 --- /dev/null +++ b/scripts/pre-link.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +if [[ "$(uname)" == "Darwin" ]]; then + echo "Preparing to link react-native-google-places for iOS" + + echo "Checking CocoaPods..." + has_cocoapods=`which pod >/dev/null 2>&1` + if [ -z "$has_cocoapods" ] + then + echo "CocoaPods already installed" + else + echo "Installing CocoaPods..." + gem install cocoapods + fi +fi