Added ability to run Movies app with BUCK

Reviewed By: mkonicek

Differential Revision: D2874873

fb-gh-sync-id: 9feface8d9a18742e68206dbafb804de25f53ed8
shipit-source-id: 9feface8d9a18742e68206dbafb804de25f53ed8
This commit is contained in:
Konstantin Raev 2016-02-25 16:39:29 -08:00 committed by facebook-github-bot-7
parent 9d3d9dfbce
commit 5112a63953
20 changed files with 158 additions and 49 deletions

View File

@ -4,3 +4,6 @@
[maven_repositories]
central = https://repo1.maven.org/maven2
[alias]
movies = //Examples/Movies/android/app:app

2
.gitignore vendored
View File

@ -29,6 +29,8 @@ project.xcworkspace
# Buck
.buckd
buck-out
/ReactAndroid/src/main/jni/prebuilt/lib/armeabi-v7a/
/ReactAndroid/src/main/jni/prebuilt/lib/x86/
# Android
.idea

View File

@ -0,0 +1,43 @@
include_defs('//ReactAndroid/DEFS')
android_binary(
name = 'app',
manifest = 'src/main/AndroidManifest.xml',
keystore = '//keystores:debug',
deps = [
':movies-lib',
],
)
android_library(
name = 'movies-lib',
srcs = glob(['src/main/java/**/*.java']),
deps = [
react_native_target('java/com/facebook/csslayout:csslayout'),
react_native_target('java/com/facebook/react:react'),
react_native_target('java/com/facebook/react/devsupport:devsupport'),
react_native_target('java/com/facebook/react/modules/core:core'),
react_native_target('java/com/facebook/react/shell:shell'),
react_native_target('java/com/facebook/react/touch:touch'),
react_native_target('java/com/facebook/react/uimanager:uimanager'),
react_native_target('java/com/facebook/react/uimanager/annotations:annotations'),
react_native_target('java/com/facebook/react/views/image:image'),
react_native_target('java/com/facebook/react/views/recyclerview:recyclerview'),
react_native_target('java/com/facebook/react/views/scroll:scroll'),
react_native_target('java/com/facebook/react/views/text:text'),
react_native_target('java/com/facebook/react/views/view:view'),
# .so files are prebuilt by Gradle with `./gradlew :ReactAndroid:packageReactNdkLibsForBuck`
react_native_target('jni/prebuilt:reactnative-libs'),
react_native_target('jni/prebuilt:android-jsc'),
react_native_dep('libraries/soloader/java/com/facebook/soloader:soloader'),
react_native_dep('third-party/java/jsr-305:jsr-305'),
':res',
],
)
android_resource(
name = 'res',
res = 'src/main/res',
package = 'com.facebook.react.movies',
)

View File

@ -3,6 +3,7 @@
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<application
android:allowBackup="true"

View File

@ -5,6 +5,7 @@
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<application
android:allowBackup="true"

View File

@ -17,10 +17,10 @@ package com.facebook.react.uiapp;
import com.facebook.react.ReactActivity;
import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage;
import com.facebook.react.uiapp.R;
import java.util.Arrays;
import java.util.List;
import javax.annotation.Nullable;
public class UIExplorerActivity extends ReactActivity {

View File

@ -204,6 +204,11 @@ task packageReactNdkLibs(dependsOn: buildReactNdkLib, type: Copy) {
into "$buildDir/react-ndk/exported"
}
task packageReactNdkLibsForBuck(dependsOn: packageReactNdkLibs, type: Copy) {
from "$buildDir/react-ndk/exported"
into "src/main/jni/prebuilt/lib"
}
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"

View File

@ -1,30 +1,10 @@
# Unpack resources from the appcompat aar and merge their ids into the
# generated com.facebook.react.R class.
#
# We do this for compatibility with Gradle: we build the open source
# version React Native with both Buck and Gradle. See for example
# ReactToolbarManager.java where we access the appcompat resources
# via com.facebook.react.R.
include_defs('//ReactAndroid/DEFS')
# used by ReactToolbarManager because of Gradle
# TODO t10182713 will be replaced with res-for-appcompat when we stop using Gradle
android_resource(
name = 'res-for-react-native',
res = ':res-unpacker-cmd',
package = 'com.facebook.react',
visibility = ['//ReactAndroid/...',],
)
genrule(
name = 'res-unpacker-cmd',
cmd = '$(exe :res-unpacker) $(location :appcompat-binary-aar) $OUT',
out = 'res',
)
python_binary(
name = 'res-unpacker',
main = 'res-unpacker.py',
)
remote_file(
name = 'appcompat-binary-aar',
url = 'mvn:com.android.support:appcompat-v7:aar:23.0.1',
sha1 = '7d659f671541394a8bc2b9f909950aa2a5ec87ff',
name = 'res-for-react-native',
res = react_native_dep('third-party/android/support/v7/appcompat-orig:res-unpacker-cmd'),
package = 'com.facebook.react',
visibility = ['//ReactAndroid/...',],
)

View File

@ -9,7 +9,6 @@ android_library(
react_native_target('java/com/facebook/csslayout:csslayout'),
react_native_target('java/com/facebook/react/uimanager:uimanager'),
react_native_target('java/com/facebook/react/uimanager/annotations:annotations'),
react_native_dep('android_res/android/support/v7/appcompat-orig:res-for-react-native'),
react_native_dep('third-party/android/support/v7/appcompat-orig:appcompat'),
react_native_dep('third-party/java/jsr-305:jsr-305'),
],

View File

@ -1,4 +1,11 @@
// Copyright 2004-present Facebook. All Rights Reserved.
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
package com.facebook.react.views.toolbar;

View File

@ -1,4 +1,11 @@
// Copyright 2004-present Facebook. All Rights Reserved.
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
package com.facebook.react.views.toolbar;

View File

@ -1,11 +1,10 @@
android_prebuilt_aar(
include_defs('//ReactAndroid/DEFS')
android_library(
name = 'logging',
aar = ':fbcore-binary-aar',
visibility = ['//ReactAndroid/...'],
exported_deps = [
react_native_dep('libraries/fresco/fresco-react-native:fbcore'),
],
visibility = ['//ReactAndroid/...',],
)
remote_file(
name = 'fbcore-binary-aar',
url = 'mvn:com.facebook.fresco:fbcore:aar:0.8.1',
sha1 = 'cc46b3d564139bf63bb41534c7a723ee8119ae5f',
)

View File

@ -1,7 +1,7 @@
android_prebuilt_aar(
name = 'lib-support-v4',
aar = ':lib-support-v4-binary-aar',
visibility = ['//ReactAndroid/...',],
visibility = ['PUBLIC',],
)
remote_file(

View File

@ -1,9 +1,59 @@
android_prebuilt_aar(
name = 'appcompat-23.1',
aar = ':appcompat-binary-aar',
include_defs('//ReactAndroid/DEFS')
# This is a bit messy and hopefully a temporary thing
# The problem is that Gradle extracts appcompat resources into app namespace, com.facebook.react
# While BUCK behaves properly and extracts them into android.support.v7.appcompat package.
# We want to support both Gradle and BUCK builds so we hack a bit how BUCK extracts resources.
# Besides that we still need JAVA classes from appcompat-v7.aar, that is why android_library
# extracts classes.jar but the trick is that we can't take full appcompat.aar because resources
# extracted from it by BUCK would conflict with resources we use under Gradelified package
# All this mumbo jumbo will go away after t10182713
android_library(
name = 'appcompat',
deps = [
':res-for-appcompat',
],
visibility = [
'PUBLIC',
],
exported_deps = [
':classes-for-react-native',
],
)
# still used by appcompat library internally, so we need both during the build
android_resource(
name = 'res-for-appcompat',
res = ':res-unpacker-cmd',
package = 'android.support.v7.appcompat',
visibility = ['//ReactAndroid/...',],
)
prebuilt_jar(
name = 'classes-for-react-native',
binary_jar = ':classes-unpacker-cmd',
visibility = ['//ReactAndroid/...',],
)
genrule(
name = 'classes-unpacker-cmd',
cmd = '$(exe :aar-unpacker) $(location :appcompat-binary-aar) "classes.jar" $OUT',
out = 'classes.jar',
)
genrule(
name = 'res-unpacker-cmd',
cmd = '$(exe :aar-unpacker) $(location :appcompat-binary-aar) "res/" $OUT',
out = 'res',
visibility = ['//ReactAndroid/...',],
)
python_binary(
name = 'aar-unpacker',
main = 'aar-unpacker.py',
)
remote_file(
name = 'appcompat-binary-aar',
url = 'mvn:com.android.support:appcompat-v7:aar:23.0.1',

View File

@ -5,7 +5,7 @@ import sys
import tempfile
import zipfile
# Helper that unpacks the contents of the res folder of an .aar file
# Helper that unpacks the contents of an .aar file
# into given destination.
@contextlib.contextmanager
@ -16,5 +16,5 @@ def cleanup(path):
if __name__ == '__main__':
with zipfile.ZipFile(sys.argv[1], 'r') as z:
with cleanup(tempfile.mkdtemp()) as temp_path:
z.extractall(temp_path, filter(lambda n: n.startswith('res/'), z.namelist()))
shutil.move(os.path.join(temp_path, 'res'), sys.argv[2])
z.extractall(temp_path, filter(lambda n: n.startswith(sys.argv[2]), z.namelist()))
shutil.move(os.path.join(temp_path, sys.argv[2]), sys.argv[3])

View File

@ -1,7 +1,7 @@
prebuilt_jar(
name = 'jsr-305',
binary_jar = ':jsr305-binary-jar',
visibility = ['//ReactAndroid/...',],
visibility = ['PUBLIC'],
)
remote_file(

View File

@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.9-bin.zip
distributionUrl=https://services.gradle.org/distributions/gradle-2.11-all.zip

8
keystores/BUCK Normal file
View File

@ -0,0 +1,8 @@
keystore(
name = 'debug',
store = 'debug.keystore',
properties = 'debug.keystore.properties',
visibility = [
'PUBLIC',
],
)

BIN
keystores/debug.keystore Normal file

Binary file not shown.

View File

@ -0,0 +1,4 @@
key.store=debug.keystore
key.alias=androiddebugkey
key.store.password=android
key.alias.password=android