fix: Distribute Android code as source (#234)
* Build Android as source * more reliably find `enableHermes`
This commit is contained in:
		
							
								
								
									
										40
									
								
								.github/workflows/build-android.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										40
									
								
								.github/workflows/build-android.yml
									
									
									
									
										vendored
									
									
								
							@@ -10,8 +10,6 @@ on:
 | 
				
			|||||||
      - 'example/android/**'
 | 
					      - 'example/android/**'
 | 
				
			||||||
      - 'yarn.lock'
 | 
					      - 'yarn.lock'
 | 
				
			||||||
      - 'example/yarn.lock'
 | 
					      - 'example/yarn.lock'
 | 
				
			||||||
      - 'scripts/build-android-npm-package.sh'
 | 
					 | 
				
			||||||
      - 'android-npm/**'
 | 
					 | 
				
			||||||
  pull_request:
 | 
					  pull_request:
 | 
				
			||||||
    paths:
 | 
					    paths:
 | 
				
			||||||
      - '.github/workflows/build-android.yml'
 | 
					      - '.github/workflows/build-android.yml'
 | 
				
			||||||
@@ -19,46 +17,8 @@ on:
 | 
				
			|||||||
      - 'example/android/**'
 | 
					      - 'example/android/**'
 | 
				
			||||||
      - 'yarn.lock'
 | 
					      - 'yarn.lock'
 | 
				
			||||||
      - 'example/yarn.lock'
 | 
					      - 'example/yarn.lock'
 | 
				
			||||||
      - 'scripts/build-android-npm-package.sh'
 | 
					 | 
				
			||||||
      - 'android-npm/**'
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
jobs:
 | 
					jobs:
 | 
				
			||||||
  build_lib:
 | 
					 | 
				
			||||||
    name: Build Android Library (.aar)
 | 
					 | 
				
			||||||
    runs-on: ubuntu-latest
 | 
					 | 
				
			||||||
    steps:
 | 
					 | 
				
			||||||
      - uses: actions/checkout@v2
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      - name: Setup JDK 1.8
 | 
					 | 
				
			||||||
        uses: actions/setup-java@v1
 | 
					 | 
				
			||||||
        with:
 | 
					 | 
				
			||||||
          java-version: 1.8
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      - name: Get yarn cache directory path
 | 
					 | 
				
			||||||
        id: yarn-cache-dir-path
 | 
					 | 
				
			||||||
        run: echo "::set-output name=dir::$(yarn cache dir)"
 | 
					 | 
				
			||||||
      - name: Restore node_modules from cache
 | 
					 | 
				
			||||||
        uses: actions/cache@v2
 | 
					 | 
				
			||||||
        id: yarn-cache
 | 
					 | 
				
			||||||
        with:
 | 
					 | 
				
			||||||
          path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
 | 
					 | 
				
			||||||
          key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
 | 
					 | 
				
			||||||
          restore-keys: |
 | 
					 | 
				
			||||||
            ${{ runner.os }}-yarn-
 | 
					 | 
				
			||||||
      - name: Install node_modules for example/
 | 
					 | 
				
			||||||
        run: yarn install --frozen-lockfile
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      - name: Restore Gradle cache
 | 
					 | 
				
			||||||
        uses: actions/cache@v2
 | 
					 | 
				
			||||||
        with:
 | 
					 | 
				
			||||||
          path: |
 | 
					 | 
				
			||||||
            ~/.gradle/caches
 | 
					 | 
				
			||||||
            ~/.gradle/wrapper
 | 
					 | 
				
			||||||
          key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
 | 
					 | 
				
			||||||
          restore-keys: |
 | 
					 | 
				
			||||||
            ${{ runner.os }}-gradle-
 | 
					 | 
				
			||||||
      - name: Build .aar
 | 
					 | 
				
			||||||
        run: scripts/build-android-npm-package.sh
 | 
					 | 
				
			||||||
  build_example:
 | 
					  build_example:
 | 
				
			||||||
    name: Build Android Example App
 | 
					    name: Build Android Example App
 | 
				
			||||||
    runs-on: ubuntu-latest
 | 
					    runs-on: ubuntu-latest
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										3
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										3
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							@@ -68,6 +68,3 @@ docs/typedoc-sidebar.js
 | 
				
			|||||||
# External native build folder generated in Android Studio 2.2 and later
 | 
					# External native build folder generated in Android Studio 2.2 and later
 | 
				
			||||||
.externalNativeBuild
 | 
					.externalNativeBuild
 | 
				
			||||||
.cxx/
 | 
					.cxx/
 | 
				
			||||||
 | 
					 | 
				
			||||||
# npm package aars
 | 
					 | 
				
			||||||
android-npm/*.aar
 | 
					 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,18 +0,0 @@
 | 
				
			|||||||
import groovy.json.JsonSlurper;
 | 
					 | 
				
			||||||
configurations.maybeCreate("default")
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
def inputFile = new File(projectDir, '../../react-native/package.json')
 | 
					 | 
				
			||||||
def json = new JsonSlurper().parseText(inputFile.text)
 | 
					 | 
				
			||||||
def reactNativeVersion = json.version as String
 | 
					 | 
				
			||||||
def (major, minor, patch) = reactNativeVersion.tokenize('.')
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
def engine = "jsc"
 | 
					 | 
				
			||||||
rootProject.getSubprojects().forEach({project ->
 | 
					 | 
				
			||||||
    if (project.plugins.hasPlugin("com.android.application")) {
 | 
					 | 
				
			||||||
        if(project.ext.react.enableHermes) {
 | 
					 | 
				
			||||||
            engine = "hermes"
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
})
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
artifacts.add("default", file("react-native-vision-camera-${engine}.aar"))
 | 
					 | 
				
			||||||
@@ -1,3 +0,0 @@
 | 
				
			|||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
 | 
					 | 
				
			||||||
          package="com.mrousavy.camera">
 | 
					 | 
				
			||||||
</manifest>
 | 
					 | 
				
			||||||
@@ -1,8 +0,0 @@
 | 
				
			|||||||
package com.mrousavy.camera;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.facebook.react.ReactPackage;
 | 
					 | 
				
			||||||
import com.mrousavy.camera.CameraPackage;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public class CameraPackage implements ReactPackage {
 | 
					 | 
				
			||||||
  // dummy package
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -4,12 +4,12 @@ import java.nio.file.Paths
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
def reactNative = new File("$projectDir/../node_modules/react-native")
 | 
					def reactNative = new File("$projectDir/../node_modules/react-native")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def FOR_HERMES = "";
 | 
					def FOR_HERMES = System.getenv("FOR_HERMES") == "True";
 | 
				
			||||||
if(findProject(':app')) {
 | 
					rootProject.getSubprojects().forEach({project ->
 | 
				
			||||||
  FOR_HERMES = project(':app').ext.react.enableHermes;
 | 
					  if (project.plugins.hasPlugin("com.android.application")) {
 | 
				
			||||||
} else {
 | 
					    FOR_HERMES = project.ext.react.enableHermes;
 | 
				
			||||||
  FOR_HERMES = System.getenv("FOR_HERMES") == "True";
 | 
					 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Finds the path of the installed npm package with the given name using Node's
 | 
					 * Finds the path of the installed npm package with the given name using Node's
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -31,7 +31,7 @@
 | 
				
			|||||||
    "typescript": "tsc --noEmit",
 | 
					    "typescript": "tsc --noEmit",
 | 
				
			||||||
    "lint": "eslint \"**/*.{js,ts,tsx}\"",
 | 
					    "lint": "eslint \"**/*.{js,ts,tsx}\"",
 | 
				
			||||||
    "lint-ci": "yarn lint -f ./node_modules/@firmnav/eslint-github-actions-formatter/dist/formatter.js",
 | 
					    "lint-ci": "yarn lint -f ./node_modules/@firmnav/eslint-github-actions-formatter/dist/formatter.js",
 | 
				
			||||||
    "build": "bob build && scripts/build-android-npm-package.sh",
 | 
					    "build": "bob build",
 | 
				
			||||||
    "release": "release-it",
 | 
					    "release": "release-it",
 | 
				
			||||||
    "pods": "cd example && yarn pods",
 | 
					    "pods": "cd example && yarn pods",
 | 
				
			||||||
    "bootstrap": "yarn && cd example && yarn && yarn pods",
 | 
					    "bootstrap": "yarn && cd example && yarn && yarn pods",
 | 
				
			||||||
@@ -42,9 +42,7 @@
 | 
				
			|||||||
    "clean-ios": "scripts/clean-ios.sh",
 | 
					    "clean-ios": "scripts/clean-ios.sh",
 | 
				
			||||||
    "clean-android": "scripts/clean-android.sh",
 | 
					    "clean-android": "scripts/clean-android.sh",
 | 
				
			||||||
    "clean-js": "scripts/clean-js.sh",
 | 
					    "clean-js": "scripts/clean-js.sh",
 | 
				
			||||||
    "docs": "cd docs && yarn build",
 | 
					    "docs": "cd docs && yarn build"
 | 
				
			||||||
    "prepack": "rm -rf android-tmp && mv android android-tmp && mv android-npm android",
 | 
					 | 
				
			||||||
    "postpack": "rm -rf android-npm && mv android android-npm && mv android-tmp android"
 | 
					 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
  "keywords": [
 | 
					  "keywords": [
 | 
				
			||||||
    "react-native",
 | 
					    "react-native",
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,26 +0,0 @@
 | 
				
			|||||||
#!/bin/bash
 | 
					 | 
				
			||||||
set -e
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
ROOT=$(pwd)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
rm -rf android-npm/*.aar
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
for for_hermes in "True" "False"
 | 
					 | 
				
			||||||
do
 | 
					 | 
				
			||||||
  engine="jsc"
 | 
					 | 
				
			||||||
  if [ "$for_hermes" == "True" ]; then
 | 
					 | 
				
			||||||
    engine="hermes"
 | 
					 | 
				
			||||||
  fi
 | 
					 | 
				
			||||||
  echo "Building VisionCamera for JS Engine ${engine}..."
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  cd android
 | 
					 | 
				
			||||||
  ./gradlew clean
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  FOR_HERMES=${for_hermes} ./gradlew assembleDebug
 | 
					 | 
				
			||||||
  cd ..
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  cp android/build/outputs/aar/*.aar "android-npm/react-native-vision-camera-${engine}.aar"
 | 
					 | 
				
			||||||
  echo "Built react-native-vision-camera-${engine}.aar!"
 | 
					 | 
				
			||||||
done
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
echo "Finished building VisionCamera packages!"
 | 
					 | 
				
			||||||
		Reference in New Issue
	
	Block a user