Skip to content

Commit 5761786

Browse files
authored
Merge pull request #2 from logicwind/dev
Dev to Master
2 parents b0a9a3c + e1cc0a7 commit 5761786

23 files changed

+479
-218
lines changed

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,22 @@ Google in-app updates support for react-native. Specially created for android on
1010

1111
`$ react-native link react-native-rn-in-app-update`
1212

13+
### Android
14+
only react-native link require
15+
16+
17+
## Linking (RN >= 0.60)
18+
19+
### Android
20+
It will auto linked after installing package
21+
22+
23+
### IOS
24+
No native implementation for ios. If project show missing pod error then perform following step:
25+
26+
```
27+
cd ios && pod install
28+
```
1329

1430
## Additional configuration in android (Required)
1531

android/build.gradle

Lines changed: 116 additions & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -1,154 +1,139 @@
1-
// android/build.gradle
2-
3-
// based on:
4-
//
5-
// * https://github.com/facebook/react-native/blob/0.60-stable/template/android/build.gradle
6-
// original location:
7-
// - https://github.com/facebook/react-native/blob/0.58-stable/local-cli/templates/HelloWorld/android/build.gradle
8-
//
9-
// * https://github.com/facebook/react-native/blob/0.60-stable/template/android/app/build.gradle
10-
// original location:
11-
// - https://github.com/facebook/react-native/blob/0.58-stable/local-cli/templates/HelloWorld/android/app/build.gradle
12-
13-
def DEFAULT_COMPILE_SDK_VERSION = 28
14-
def DEFAULT_BUILD_TOOLS_VERSION = '28.0.3'
15-
def DEFAULT_MIN_SDK_VERSION = 16
16-
def DEFAULT_TARGET_SDK_VERSION = 28
17-
18-
def safeExtGet(prop, fallback) {
19-
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
1+
buildscript {
2+
repositories {
3+
google()
4+
mavenCentral()
5+
}
6+
7+
dependencies {
8+
classpath 'com.android.tools.build:gradle:3.5.3'
9+
}
2010
}
2111

22-
apply plugin: 'com.android.library'
23-
apply plugin: 'maven'
24-
25-
buildscript {
26-
// The Android Gradle plugin is only required when opening the android folder stand-alone.
27-
// This avoids unnecessary downloads and potential conflicts when the library is included as a
28-
// module dependency in an application project.
29-
// ref: https://docs.gradle.org/current/userguide/tutorial_using_tasks.html#sec:build_script_external_dependencies
30-
if (project == rootProject) {
31-
repositories {
32-
google()
33-
jcenter()
34-
}
35-
dependencies {
36-
classpath 'com.android.tools.build:gradle:3.4.1'
37-
}
38-
}
12+
def isNewArchitectureEnabled() {
13+
return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true"
3914
}
4015

4116
apply plugin: 'com.android.library'
42-
apply plugin: 'maven'
4317

44-
android {
45-
compileSdkVersion safeExtGet('compileSdkVersion', DEFAULT_COMPILE_SDK_VERSION)
46-
buildToolsVersion safeExtGet('buildToolsVersion', DEFAULT_BUILD_TOOLS_VERSION)
47-
defaultConfig {
48-
minSdkVersion safeExtGet('minSdkVersion', DEFAULT_MIN_SDK_VERSION)
49-
targetSdkVersion safeExtGet('targetSdkVersion', DEFAULT_TARGET_SDK_VERSION)
50-
versionCode 1
51-
versionName "1.0"
52-
}
53-
lintOptions {
54-
abortOnError false
55-
}
56-
compileOptions {
57-
sourceCompatibility = 1.8
58-
targetCompatibility = 1.8
59-
}
18+
if (isNewArchitectureEnabled()) {
19+
apply plugin: 'com.facebook.react'
6020
}
6121

62-
repositories {
63-
// ref: https://www.baeldung.com/maven-local-repository
64-
mavenLocal()
65-
maven {
66-
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
67-
url "$rootDir/../node_modules/react-native/android"
68-
}
69-
maven {
70-
// Android JSC is installed from npm
71-
url "$rootDir/../node_modules/jsc-android/dist"
72-
}
73-
google()
74-
jcenter()
22+
def getExtOrDefault(name) {
23+
return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties['RnInAppUpdate_' + name]
7524
}
7625

77-
dependencies {
78-
//noinspection GradleDynamicVersion
79-
implementation 'com.facebook.react:react-native:+' // From node_modules
80-
implementation 'com.google.android.play:core:1.7.3'
26+
def getExtOrIntegerDefault(name) {
27+
return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties['RnInAppUpdate_' + name]).toInteger()
8128
}
8229

83-
def configureReactNativePom(def pom) {
84-
def packageJson = new groovy.json.JsonSlurper().parseText(file('../package.json').text)
85-
86-
pom.project {
87-
name packageJson.title
88-
artifactId packageJson.name
89-
version = packageJson.version
90-
group = "com.reactlibrary.inappupdate"
91-
description packageJson.description
92-
url packageJson.repository.baseUrl
93-
94-
licenses {
95-
license {
96-
name packageJson.license
97-
url packageJson.repository.baseUrl + '/blob/master/' + packageJson.licenseFilename
98-
distribution 'repo'
99-
}
100-
}
101-
102-
developers {
103-
developer {
104-
id packageJson.author.username
105-
name packageJson.author.name
106-
}
107-
}
30+
android {
31+
compileSdkVersion getExtOrIntegerDefault('compileSdkVersion')
32+
33+
defaultConfig {
34+
minSdkVersion getExtOrIntegerDefault('minSdkVersion')
35+
targetSdkVersion getExtOrIntegerDefault('targetSdkVersion')
36+
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
37+
}
38+
buildTypes {
39+
release {
40+
minifyEnabled false
10841
}
109-
}
42+
}
11043

111-
afterEvaluate { project ->
112-
// some Gradle build hooks ref:
113-
// https://www.oreilly.com/library/view/gradle-beyond-the/9781449373801/ch03.html
114-
task androidJavadoc(type: Javadoc) {
115-
source = android.sourceSets.main.java.srcDirs
116-
classpath += files(android.bootClasspath)
117-
classpath += files(project.getConfigurations().getByName('compile').asList())
118-
include '**/*.java'
119-
}
44+
lintOptions {
45+
disable 'GradleCompatible'
46+
}
12047

121-
task androidJavadocJar(type: Jar, dependsOn: androidJavadoc) {
122-
classifier = 'javadoc'
123-
from androidJavadoc.destinationDir
124-
}
48+
compileOptions {
49+
sourceCompatibility JavaVersion.VERSION_1_8
50+
targetCompatibility JavaVersion.VERSION_1_8
51+
}
52+
}
12553

126-
task androidSourcesJar(type: Jar) {
127-
classifier = 'sources'
128-
from android.sourceSets.main.java.srcDirs
129-
include '**/*.java'
54+
repositories {
55+
mavenCentral()
56+
google()
57+
58+
def found = false
59+
def defaultDir = null
60+
def androidSourcesName = 'React Native sources'
61+
62+
if (rootProject.ext.has('reactNativeAndroidRoot')) {
63+
defaultDir = rootProject.ext.get('reactNativeAndroidRoot')
64+
} else {
65+
defaultDir = new File(
66+
projectDir,
67+
'/../../../node_modules/react-native/android'
68+
)
69+
}
70+
71+
if (defaultDir.exists()) {
72+
maven {
73+
url defaultDir.toString()
74+
name androidSourcesName
13075
}
13176

132-
android.libraryVariants.all { variant ->
133-
def name = variant.name.capitalize()
134-
def javaCompileTask = variant.javaCompileProvider.get()
77+
logger.info(":${project.name}:reactNativeAndroidRoot ${defaultDir.canonicalPath}")
78+
found = true
79+
} else {
80+
def parentDir = rootProject.projectDir
81+
82+
1.upto(5, {
83+
if (found) return true
84+
parentDir = parentDir.parentFile
85+
86+
def androidSourcesDir = new File(
87+
parentDir,
88+
'node_modules/react-native'
89+
)
90+
91+
def androidPrebuiltBinaryDir = new File(
92+
parentDir,
93+
'node_modules/react-native/android'
94+
)
95+
96+
if (androidPrebuiltBinaryDir.exists()) {
97+
maven {
98+
url androidPrebuiltBinaryDir.toString()
99+
name androidSourcesName
100+
}
135101

136-
task "jar${name}"(type: Jar, dependsOn: javaCompileTask) {
137-
from javaCompileTask.destinationDir
102+
logger.info(":${project.name}:reactNativeAndroidRoot ${androidPrebuiltBinaryDir.canonicalPath}")
103+
found = true
104+
} else if (androidSourcesDir.exists()) {
105+
maven {
106+
url androidSourcesDir.toString()
107+
name androidSourcesName
138108
}
139-
}
140109

141-
artifacts {
142-
archives androidSourcesJar
143-
archives androidJavadocJar
144-
}
110+
logger.info(":${project.name}:reactNativeAndroidRoot ${androidSourcesDir.canonicalPath}")
111+
found = true
112+
}
113+
})
114+
}
115+
116+
if (!found) {
117+
throw new GradleException(
118+
"${project.name}: unable to locate React Native android sources. " +
119+
"Ensure you have you installed React Native as a dependency in your project and try again."
120+
)
121+
}
122+
}
145123

146-
task installArchives(type: Upload) {
147-
configuration = configurations.archives
148-
repositories.mavenDeployer {
149-
// Deploy to react-native-event-bridge/maven, ready to publish to npm
150-
repository url: "file://${projectDir}/../android/maven"
151-
configureReactNativePom pom
152-
}
153-
}
124+
125+
dependencies {
126+
//noinspection GradleDynamicVersion
127+
implementation "com.facebook.react:react-native:+"
128+
// implementation 'com.google.android.play:app-update:2.0.0'
129+
// From node_modules
130+
implementation 'com.google.android.play:core:1.10.3'
131+
}
132+
133+
if (isNewArchitectureEnabled()) {
134+
react {
135+
jsRootDir = file("../src/")
136+
libraryName = "RnInAppUpdate"
137+
codegenJavaPackageName = "com.logicwind.inappupdate"
138+
}
154139
}

android/gradle.properties

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
RnInAppUpdate_kotlinVersion=1.7.0
2+
RnInAppUpdate_minSdkVersion=21
3+
RnInAppUpdate_targetSdkVersion=31
4+
RnInAppUpdate_compileSdkVersion=31
5+
RnInAppUpdate_ndkversion=21.4.7075529
5.08 KB
Binary file not shown.
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
#Sat Jun 27 19:12:06 IST 2020
21
distributionBase=GRADLE_USER_HOME
32
distributionPath=wrapper/dists
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.1-bin.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip

0 commit comments

Comments
 (0)