Skip to content

Commit

Permalink
feat(native): native code extraction is complete and passes static ty…
Browse files Browse the repository at this point in the history
…pe check

example app still not functional but all the code exists now
  • Loading branch information
mikehardy committed Sep 1, 2021
1 parent 2b0c017 commit 02c2af6
Show file tree
Hide file tree
Showing 73 changed files with 6,691 additions and 2 deletions.
42 changes: 42 additions & 0 deletions RNAdMob.podspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
require 'json'
package = JSON.parse(File.read(File.join(__dir__, 'package.json')))

admob_sdk_version = package['sdkVersions']['ios']['admob']

Pod::Spec.new do |s|
s.name = "RNAdMob"

s.version = package["version"]
s.description = package["description"]
s.summary = <<-DESC
A well tested feature rich AdMob implementation for React Native, supporting iOS & Android.
DESC
s.homepage = "http://invertase.io/oss/react-native-admob"
s.license = package['license']
s.authors = "Invertase Limited"
s.source = { :git => "https://github.com/invertase/react-native-admob.git", :tag => "v#{s.version}" }
s.social_media_url = 'http://twitter.com/invertaseio'
s.ios.deployment_target = "10.0"
s.source_files = 'ios/**/*.{h,m}'

# React Native dependencies
s.dependency 'React-Core'

# Other dependencies
s.dependency 'PersonalizedAdConsent', '~> 1.0.5'

if defined?($RNAdMobSDKVersion)
Pod::UI.puts "#{s.name}: Using user specified Google Mobile-Ads SDK version '#{$RNAdMobSDKVersion}'"
admob_sdk_version = $RNAdMobSDKVersion
end

# AdMob dependencies
s.dependency 'Google-Mobile-Ads-SDK', admob_sdk_version

if defined?($RNAdMobAsStaticFramework)
Pod::UI.puts "#{s.name}: Using overridden static_framework value of '#{$RNAdMobAsStaticFramework}'"
s.static_framework = $RNAdMobAsStaticFramework
else
s.static_framework = false
end
end
10 changes: 10 additions & 0 deletions android/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# editorconfig
root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
68 changes: 68 additions & 0 deletions android/admob-json.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import groovy.json.JsonOutput
import groovy.json.JsonSlurper

String fileName = "admob.json"
String jsonRoot = "react-native"

File jsonFile = null
File parentDir = rootProject.projectDir

for (int i = 0; i <= 3; i++) {
if (parentDir == null) break
parentDir = parentDir.parentFile
if (parentDir != null) {
jsonFile = new File(parentDir, fileName)
if (jsonFile.exists()) break
}
}

if (jsonFile != null && jsonFile.exists()) {
rootProject.logger.info ":${project.name} admob.json found at ${jsonFile.toString()}"
Object json = null

try {
json = new JsonSlurper().parseText(jsonFile.text)
} catch (Exception ignored) {
rootProject.logger.warn ":${project.name} failed to parse admob.json found at ${jsonFile.toString()}."
rootProject.logger.warn ignored.toString()
}

if (json && json[jsonRoot]) {
String jsonStr = JsonOutput.toJson(JsonOutput.toJson(json[jsonRoot]))

rootProject.ext.admobJson = [
raw: json[jsonRoot],
isFlagEnabled: { key, defaultValue ->
if (json[jsonRoot] == null || json[jsonRoot][key] == null) return defaultValue
return json[jsonRoot][key] == true ? true : false
},
getStringValue: { key, defaultValue ->
if (json[jsonRoot] == null) return defaultValue
return json[jsonRoot][key] ? json[jsonRoot][key] : defaultValue
}
]

rootProject.logger.info ":${project.name} found react-native json root in admob.json, creating admob build config"
android {
defaultConfig {
buildConfigField "String", "ADMOB_JSON_RAW", jsonStr
}
}
} else {
rootProject.ext.admobJson = false
rootProject.logger.info ":${project.name} admob.json found with no react-native config, skipping"
android {
defaultConfig {
buildConfigField "String", "ADMOB_JSON_RAW", '"{}"'
}
}
}
} else {
rootProject.ext.admobJson = false
rootProject.logger.info ":${project.name} no admob.json found, skipping"
android {
defaultConfig {
buildConfigField "String", "ADMOB_JSON_RAW", '"{}"'
}
}
}
98 changes: 98 additions & 0 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import io.invertase.gradle.common.PackageJson

buildscript {
// The Android Gradle plugin is only required when opening the android folder stand-alone.
// This avoids unnecessary downloads and potential conflicts when the library is included as a
// module dependency in an application project.
if (project == rootProject) {
repositories {
google()
mavenCentral()
}

dependencies {
classpath("com.android.tools.build:gradle:7.0.1")
}
}
}

plugins {
id "io.invertase.gradle.build" version "1.5"
}

def packageJson = PackageJson.getForProject(project)
def admobVersion = packageJson['sdkVersions']['android']['admob']
def jsonMinSdk = packageJson['sdkVersions']['android']['minSdk']
def jsonTargetSdk = packageJson['sdkVersions']['android']['targetSdk']
def jsonCompileSdk = packageJson['sdkVersions']['android']['compileSdk']
def jsonBuildTools = packageJson['sdkVersions']['android']['buildTools']

project.ext {
set('react-native', [
versions: [
android : [
minSdk : jsonMinSdk,
targetSdk : jsonTargetSdk,
compileSdk: jsonCompileSdk,
// optional as gradle.buildTools comes with one by default
// overriding here though to match the version RN uses
buildTools: jsonBuildTools
],

admob: [
sdk: admobVersion,
],

ads : [
consent: "1.0.6"
],
],
])
}

apply from: file("./admob-json.gradle")

def admobJSONAdmobAppIDString = ""
def admobJSONAdmobDelayAppMeasurementInitBool = false

if (rootProject.ext.admobJson) {
admobJSONAdmobAppIDString = rootProject.ext.admobJson.getStringValue("android_app_id", "")
admobJSONAdmobDelayAppMeasurementInitBool = rootProject.ext.admobJson.isFlagEnabled("delay_app_measurement_init", false)
}

if (!admobJSONAdmobAppIDString) {
// todo throw a build error?
}

android {
defaultConfig {
multiDexEnabled true
manifestPlaceholders = [
admobJSONAdmobAppID : admobJSONAdmobAppIDString,
admobJSONAdmobDelayAppMeasurementInit: admobJSONAdmobDelayAppMeasurementInitBool
]
}
lintOptions {
disable 'GradleCompatible'
abortOnError false
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

repositories {
google()
mavenCentral()
}

dependencies {
implementation("com.google.android.gms:play-services-ads:19.8.0") { force = true; }
implementation "com.google.android.ads.consent:consent-library:${ReactNative.ext.getVersion("ads", "consent")}"
}

ReactNative.shared.applyPackageVersion()
ReactNative.shared.applyDefaultExcludes()
ReactNative.module.applyAndroidVersions()
ReactNative.module.applyReactNativeDependency("api")
5 changes: 5 additions & 0 deletions android/lint.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<lint>
<!-- Disable the given check in this project -->
<issue id="GradleCompatible" severity="ignore" />
</lint>
1 change: 1 addition & 0 deletions android/settings.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rootProject.name = '@invertase_react-native-admob'
17 changes: 17 additions & 0 deletions android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="io.invertase.admob">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<application>
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="${admobJSONAdmobAppID}"/>
<meta-data
android:name="com.google.android.gms.ads.DELAY_APP_MEASUREMENT_INIT"
android:value="${admobJSONAdmobDelayAppMeasurementInit}"/>
</application>
</manifest>
Loading

0 comments on commit 02c2af6

Please sign in to comment.