Skip to content

Commit e9e8b10

Browse files
authored
Petterh/azure devops (#12)
* Diagnostics for Azure DevOps issue * Update azure-pipelines.yml for Azure Pipelines * Add build status banner * Find React Native location and version dynamically * Remove BUCK stuff * Remove package-lock.json * Tweak react versions: expo/expo#3949
1 parent b1d49c2 commit e9e8b10

File tree

7 files changed

+148
-97
lines changed

7 files changed

+148
-97
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# React Native Activity Demo
22

3+
[![Build Status](https://dev.azure.com/petter0012/react-native-android-activity/_apis/build/status/petterh.react-native-android-activity?branchName=master)](https://dev.azure.com/petter0012/react-native-android-activity/_build/latest?definitionId=1&branchName=master)
4+
35
This sample, which grew out of a [question on Stack Overflow](https://stackoverflow.com/questions/42253397/call-android-activity-from-react-native-code/43675819), demonstrates the interface between React Native JavaScript and Java code in host applications.
46

57
The original version was Android-only; support for iOS was added March 28 2019.

android/app/build.gradle

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ import com.android.build.OutputFile
1515
* https://github.com/facebook/react-native/pull/21408
1616
*/
1717

18-
def bundleInDebug = hasProperty("bundleInDebug") && Boolean.valueOf(property("bundleInDebug"))
19-
def useDevSupport = !bundleInDebug
18+
final bundleInDebug = hasProperty("bundleInDebug") && Boolean.valueOf(property("bundleInDebug"))
19+
final useDevSupport = !bundleInDebug
2020

2121
project.ext.react = [
2222
// The name of the generated asset file containing your JS bundle
@@ -83,12 +83,12 @@ apply from: "../../node_modules/react-native/react.gradle"
8383
* Upload all the APKs to the Play Store and people will download
8484
* the correct one based on the CPU architecture of their device.
8585
*/
86-
def enableSeparateBuildPerCPUArchitecture = false
86+
final enableSeparateBuildPerCPUArchitecture = false
8787

8888
/**
8989
* Run Proguard to shrink the Java bytecode in release builds.
9090
*/
91-
def enableProguardInReleaseBuilds = false
91+
final enableProguardInReleaseBuilds = false
9292

9393
android {
9494
compileSdkVersion 28
@@ -109,7 +109,7 @@ android {
109109
abi {
110110
reset()
111111
enable enableSeparateBuildPerCPUArchitecture
112-
universalApk false // If true, also generate a universal APK
112+
universalApk false // If true, also generate a universal APK
113113
include 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64'
114114
}
115115
}
@@ -139,7 +139,7 @@ android {
139139
}
140140
}
141141

142-
// This is necessary to include the JavaScript bundle in the APK:
142+
// Ensure that the JavaScript bundle is included in the APK:
143143
sourceSets {
144144
main {
145145
debug {
@@ -157,14 +157,7 @@ android {
157157
dependencies {
158158
implementation fileTree(dir: 'libs', include: ['*.jar'])
159159
implementation 'com.android.support:appcompat-v7:28.0.0'
160-
implementation('com.facebook.react:react-native:0.59.9') {
160+
implementation("com.facebook.react:react-native:$rootProject.ext.reactNativeVersion") {
161161
exclude group: 'com.android.support'
162162
}
163163
}
164-
165-
// Run this once to be able to run the application with BUCK
166-
// puts all compile dependencies into folder libs for BUCK to use
167-
task copyDownloadableDepsToLibs(type: Copy) {
168-
from configurations.compile
169-
into 'libs'
170-
}

android/build.gradle

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import groovy.json.JsonSlurper
2+
13
// Top-level build file where you can add configuration options common to all sub-projects/modules.
24

35
buildscript {
@@ -6,7 +8,7 @@ buildscript {
68
google()
79
}
810
dependencies {
9-
classpath 'com.android.tools.build:gradle:3.4.1'
11+
classpath 'com.android.tools.build:gradle:3.4.2'
1012

1113
// NOTE: Do not place your application dependencies here; they belong
1214
// in the individual module build.gradle files
@@ -17,11 +19,58 @@ allprojects {
1719
repositories {
1820
maven {
1921
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
20-
url "$rootDir/../node_modules/react-native/android"
22+
url findReactNative()
2123
}
2224

2325
mavenLocal()
2426
jcenter()
2527
google()
2628
}
2729
}
30+
31+
final findReactNative() {
32+
final reactNativePath = 'node_modules/react-native/android'
33+
final notFoundMessage = 'Unable to find React Native. Have you run yarn from the root?'
34+
35+
def root = file("$rootDir")
36+
if (root == null) {
37+
throw new GradleException(notFoundMessage)
38+
}
39+
40+
def reactNativeDir = new File(root, reactNativePath);
41+
while (!reactNativeDir.exists()) {
42+
root = root.parentFile
43+
if (root == null) {
44+
throw new GradleException(notFoundMessage)
45+
}
46+
47+
reactNativeDir = new File(root, reactNativePath);
48+
}
49+
50+
return reactNativeDir.toString()
51+
}
52+
53+
ext {
54+
reactNativeVersion = getReactNativeVersion()
55+
}
56+
57+
/**
58+
* Get the React Native version from package.json
59+
*/
60+
final getReactNativeVersion() {
61+
final json = new JsonSlurper()
62+
final packageJsonFile = file('../package.json')
63+
if (!packageJsonFile.exists()) {
64+
throw new Exception('No package.json found')
65+
}
66+
67+
final packageJson = json.parse packageJsonFile
68+
final reactNativeVersion = packageJson.dependencies."react-native"
69+
if (!reactNativeVersion) {
70+
throw new Exception('No react native version found in package.json dependencies')
71+
}
72+
73+
println "React native version: $reactNativeVersion"
74+
75+
return reactNativeVersion
76+
}

android/gradle.properties

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryErro
1717
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
1818
# org.gradle.parallel=true
1919

20-
android.useDeprecatedNdk=true
2120
android.debug.obsoleteApi=true
2221

2322
bundleInDebug=true

azure-pipelines.yml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,11 @@ steps:
1515
versionSpec: '10.x'
1616
displayName: 'Install Node.js'
1717

18-
- script: |
19-
npm install
20-
pwd
21-
ls android/*
22-
ls node_modules/react-native/*
18+
- task: Npm@1
19+
inputs:
20+
command: 'install'
2321
displayName: 'npm install'
24-
22+
2523
- task: Gradle@2
2624
inputs:
2725
gradleWrapperFile: 'android/gradlew'

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@
33
"repository": {
44
"type": "git",
55
"url": "https://github.com/petterh/react-native-android-activity.git"
6-
},
7-
"version": "5.0.0",
6+
},
7+
"version": "5.0.2",
88
"private": true,
99
"scripts": {
1010
"start": "node node_modules/react-native/local-cli/cli.js start"
1111
},
1212
"dependencies": {
13-
"react": "^16.8.6",
14-
"react-native": "^0.59.9"
13+
"react": "16.8.3",
14+
"react-native": "0.59.9"
1515
},
1616
"devDependencies": {
1717
"babel-loader": "8.0.6",
1818
"babel-plugin-transform-runtime": "6.23.0",
19-
"metro-react-native-babel-preset": "^0.54.1"
19+
"metro-react-native-babel-preset": "0.55.0"
2020
}
2121
}

0 commit comments

Comments
 (0)