-
Notifications
You must be signed in to change notification settings - Fork 68
Binary package build #44
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
Changes from all commits
7155c9d
aa9e768
2eba9c6
502f822
1b775bc
b1b9123
cb4cf61
b3c66d2
6787cc8
04c540e
268e577
1822659
c084daf
2482684
b2e9f3a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| Assembled | ||
| Build | ||
| node_modules |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,161 @@ | ||
| // android/build.gradle | ||
|
|
||
| // based on: | ||
| // | ||
| // * https://github.com/facebook/react-native/blob/0.60-stable/template/android/build.gradle | ||
| // original location: | ||
| // - https://github.com/facebook/react-native/blob/0.58-stable/local-cli/templates/HelloWorld/android/build.gradle | ||
| // | ||
| // * https://github.com/facebook/react-native/blob/0.60-stable/template/android/app/build.gradle | ||
| // original location: | ||
| // - https://github.com/facebook/react-native/blob/0.58-stable/local-cli/templates/HelloWorld/android/app/build.gradle | ||
|
|
||
| def DEFAULT_COMPILE_SDK_VERSION = 28 | ||
| def DEFAULT_BUILD_TOOLS_VERSION = '28.0.3' | ||
| def DEFAULT_MIN_SDK_VERSION = 18 | ||
| def DEFAULT_TARGET_SDK_VERSION = 28 | ||
|
|
||
| def safeExtGet(prop, fallback) { | ||
| rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback | ||
| } | ||
|
|
||
| apply plugin: 'com.android.library' | ||
| apply plugin: 'maven' | ||
|
|
||
| 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. | ||
| // ref: https://docs.gradle.org/current/userguide/tutorial_using_tasks.html#sec:build_script_external_dependencies | ||
| if (project == rootProject) { | ||
| repositories { | ||
| google() | ||
| jcenter() | ||
| } | ||
| dependencies { | ||
| classpath 'com.android.tools.build:gradle:3.4.1' | ||
| } | ||
| } | ||
| } | ||
|
|
||
| apply plugin: 'com.android.library' | ||
| apply plugin: 'maven' | ||
|
|
||
| android { | ||
| compileSdkVersion safeExtGet('compileSdkVersion', DEFAULT_COMPILE_SDK_VERSION) | ||
| buildToolsVersion safeExtGet('buildToolsVersion', DEFAULT_BUILD_TOOLS_VERSION) | ||
| defaultConfig { | ||
| minSdkVersion safeExtGet('minSdkVersion', DEFAULT_MIN_SDK_VERSION) | ||
| targetSdkVersion safeExtGet('targetSdkVersion', DEFAULT_TARGET_SDK_VERSION) | ||
| versionCode 1 | ||
| versionName "1.0" | ||
| } | ||
| lintOptions { | ||
| abortOnError false | ||
| } | ||
| compileOptions { | ||
| sourceCompatibility JavaVersion.VERSION_1_8 | ||
| targetCompatibility JavaVersion.VERSION_1_8 | ||
| } | ||
| } | ||
|
|
||
| repositories { | ||
| // ref: https://www.baeldung.com/maven-local-repository | ||
| mavenLocal() | ||
| maven { | ||
| // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm | ||
| url "$rootDir/../node_modules/react-native/android" | ||
| } | ||
| maven { | ||
| // Android JSC is installed from npm | ||
| url "$rootDir/../node_modules/jsc-android/dist" | ||
| } | ||
| google() | ||
| jcenter() | ||
| } | ||
|
|
||
| dependencies { | ||
| //noinspection GradleDynamicVersion | ||
| implementation 'com.facebook.react:react-native:+' // From node_modules | ||
| implementation 'com.google.ar:core:1.14.0' | ||
| } | ||
|
|
||
| def configureReactNativePom(def pom) { | ||
| def packageJson = new groovy.json.JsonSlurper().parseText(file('../package.json').text) | ||
|
|
||
| pom.project { | ||
| name packageJson.title | ||
| artifactId packageJson.name | ||
| version = packageJson.version | ||
| group = "com.reactlibrary" | ||
| description packageJson.description | ||
| url packageJson.repository.baseUrl | ||
|
|
||
| licenses { | ||
| license { | ||
| name packageJson.license | ||
| url packageJson.repository.baseUrl + '/blob/master/' + packageJson.licenseFilename | ||
| distribution 'repo' | ||
| } | ||
| } | ||
|
|
||
| developers { | ||
| developer { | ||
| id packageJson.author.username | ||
| name packageJson.author.name | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| afterEvaluate { project -> | ||
| // some Gradle build hooks ref: | ||
| // https://www.oreilly.com/library/view/gradle-beyond-the/9781449373801/ch03.html | ||
| task androidJavadoc(type: Javadoc) { | ||
| source = android.sourceSets.main.java.srcDirs | ||
| classpath += files(android.bootClasspath) | ||
| classpath += files(project.getConfigurations().getByName('compile').asList()) | ||
| include '**/*.java' | ||
| } | ||
|
|
||
| task androidJavadocJar(type: Jar, dependsOn: androidJavadoc) { | ||
| classifier = 'javadoc' | ||
| from androidJavadoc.destinationDir | ||
| } | ||
|
|
||
| task androidSourcesJar(type: Jar) { | ||
| classifier = 'sources' | ||
| from android.sourceSets.main.java.srcDirs | ||
| include '**/*.java' | ||
| } | ||
|
|
||
| android.libraryVariants.all { variant -> | ||
| def name = variant.name.capitalize() | ||
| def javaCompileTask = variant.javaCompileProvider.get() | ||
|
|
||
| task "jar${name}"(type: Jar, dependsOn: javaCompileTask) { | ||
| from javaCompileTask.destinationDir | ||
| } | ||
| } | ||
|
|
||
| artifacts { | ||
| archives androidSourcesJar | ||
| archives androidJavadocJar | ||
| } | ||
|
|
||
| task installArchives(type: Upload) { | ||
| configuration = configurations.archives | ||
| repositories.mavenDeployer { | ||
| // Deploy to react-native-event-bridge/maven, ready to publish to npm | ||
| repository url: "file://${projectDir}/../android/maven" | ||
| configureReactNativePom pom | ||
| } | ||
| } | ||
| } | ||
|
|
||
| task validateSdk { | ||
| def minSdkVersion = safeExtGet('minSdkVersion', DEFAULT_MIN_SDK_VERSION) | ||
| if (minSdkVersion < DEFAULT_MIN_SDK_VERSION) { | ||
| throw new GradleException("minSdkVersion must be at least ${DEFAULT_MIN_SDK_VERSION} but is currently ${minSdkVersion}") | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| const util = require('util'); | ||
| const fs = require('fs'); | ||
| const readdirAsync = util.promisify(fs.readdir); | ||
| const log = require('fancy-log'); | ||
| const gulp = require('gulp'); | ||
| const shelljs = require('shelljs'); | ||
|
|
||
| function exec(command, workingDirectory = '.', logCommand = true) { | ||
| if (logCommand) { | ||
| log(command); | ||
| } | ||
|
|
||
| shelljs.pushd('-q', workingDirectory); | ||
| try { | ||
| if (shelljs.exec(command, {fatal: true}).code) { | ||
| throw `'${command}' finished with non-zero exit code.`; | ||
| } | ||
| } finally { | ||
| shelljs.popd('-q'); | ||
| } | ||
| } | ||
|
|
||
| const clean = async () => { | ||
| if (shelljs.test('-d', 'Assembled')) { | ||
| shelljs.rm('-r', 'Assembled'); | ||
| } | ||
| }; | ||
|
|
||
| const makeXCodeProj = async () => { | ||
| shelljs.mkdir('-p', 'iOS/Build'); | ||
| exec('cmake -G Xcode -DCMAKE_TOOLCHAIN_FILE=../../../Apps/Playground/node_modules/@babylonjs/react-native/submodules/BabylonNative/Dependencies/ios-cmake/ios.toolchain.cmake -DPLATFORM=OS64COMBINED -DENABLE_ARC=0 -DDEPLOYMENT_TARGET=12 -DENABLE_GLSLANG_BINARIES=OFF -DSPIRV_CROSS_CLI=OFF ..', 'iOS/Build'); | ||
| }; | ||
|
|
||
| const buildIphoneOS = async () => { | ||
| exec('xcodebuild -sdk iphoneos -configuration Release -project ReactNativeBabylon.xcodeproj -scheme BabylonNative build CODE_SIGNING_ALLOWED=NO', 'iOS/Build'); | ||
| }; | ||
|
|
||
| const buildIphoneSimulator = async () => { | ||
| exec('xcodebuild -sdk iphonesimulator -configuration Release -project ReactNativeBabylon.xcodeproj -scheme BabylonNative build CODE_SIGNING_ALLOWED=NO', 'iOS/Build'); | ||
| }; | ||
|
|
||
| const buildIOS = gulp.series(makeXCodeProj, buildIphoneOS, buildIphoneSimulator); | ||
|
|
||
| const buildAndroid = async () => { | ||
| exec('./gradlew babylonjs_react-native:assembleRelease', '../Apps/Playground/android'); | ||
| }; | ||
|
|
||
| const copyCommonFiles = () => { | ||
| return gulp.src('../Apps/Playground/node_modules/@babylonjs/react-native/package.json') | ||
| .pipe(gulp.src('../Apps/Playground/node_modules/@babylonjs/react-native/README.md')) | ||
| .pipe(gulp.src('../Apps/Playground/node_modules/@babylonjs/react-native/*.ts*')) | ||
| .pipe(gulp.src('react-native-babylon.podspec')) | ||
| .pipe(gulp.dest('Assembled')); | ||
| }; | ||
|
|
||
| const copyIOSFiles = () => { | ||
| return gulp.src('../Apps/Playground/node_modules/@babylonjs/react-native/ios/*.h') | ||
| .pipe(gulp.src('../Apps/Playground/node_modules/@babylonjs/react-native/ios/*.mm')) | ||
| // This xcodeproj is garbage that we don't need in the package, but `pod install` ignores the package if it doesn't contain at least one xcodeproj. 🤷🏼♂️ | ||
| .pipe(gulp.src('iOS/Build/ReactNativeBabylon.xcodeproj**/**/*')) | ||
| .pipe(gulp.dest('Assembled/ios')); | ||
| }; | ||
|
|
||
| const createIOSUniversalLibs = async () => { | ||
| shelljs.mkdir('-p', 'Assembled/ios/libs'); | ||
| const libs = await readdirAsync('iOS/Build/Release-iphoneos'); | ||
| libs.map(lib => exec(`lipo -create iOS/Build/Release-iphoneos/${lib} iOS/Build/Release-iphonesimulator/${lib} -output Assembled/ios/libs/${lib}`)); | ||
| }; | ||
|
|
||
| const copyAndroidFiles = async () => { | ||
| await new Promise(resolve => { | ||
| gulp.src('Android/build.gradle') | ||
| .pipe(gulp.src('../Apps/Playground/node_modules/@babylonjs/react-native/android/src**/main/AndroidManifest.xml')) | ||
| .pipe(gulp.src('../Apps/Playground/node_modules/@babylonjs/react-native/android/src**/main/java/**/*')) | ||
| .pipe(gulp.dest('Assembled/android')) | ||
| .on('end', resolve); | ||
| }); | ||
|
|
||
| await new Promise(resolve => { | ||
| gulp.src('../Apps/Playground/node_modules/@babylonjs/react-native/android/build/intermediates/library_and_local_jars_jni/release/jni/**/*') | ||
| .pipe(gulp.dest('Assembled/android/src/main/jniLibs/')) | ||
| .on('end', resolve); | ||
| }); | ||
| }; | ||
|
|
||
| const createPackage = async () => { | ||
| exec('npm pack', 'Assembled'); | ||
| }; | ||
|
|
||
| const copyFiles = gulp.parallel(copyCommonFiles, copyIOSFiles, copyAndroidFiles); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't understand the difference between gulp.parallel and Promise.all. Why use one vs. the other?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Gulp functions/tasks can return Promises, but they can also return a variety of other objects representing asynchronous work (such as those using the src/pipe/dest stuff). |
||
|
|
||
| const build = gulp.series(buildIOS, buildAndroid, createIOSUniversalLibs, copyFiles); | ||
| const rebuild = gulp.series(clean, build); | ||
| const pack = gulp.series(rebuild, createPackage); | ||
|
|
||
| exports.buildIOS = buildIOS; | ||
| exports.buildAndroid = buildAndroid; | ||
| exports.createIOSUniversalLibs = createIOSUniversalLibs; | ||
| exports.copyFiles = copyFiles; | ||
|
|
||
| exports.clean = clean; | ||
| exports.build = build; | ||
| exports.rebuild = rebuild; | ||
| exports.pack = pack; | ||
|
|
||
| exports.default = build; | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is using
new Promisereally necessary here? Seems like you can usegulp.parallellike below?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, if i use
gulp.parallel, then Gulp treats these as individual atomic "tasks." I think it makes more sense to have these grouped together in a single "logical task."There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean use gulp.parallel on the "tasks" returned by each section of the gulp.pipe.pipe:
Does this work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, that will create two nodes in the task hierarchy named "anonymous function" (or something like that). Talked offline, leaving as is.