Skip to content
This repository has been archived by the owner on Mar 28, 2024. It is now read-only.

Commit

Permalink
Added ability to run Movies app with BUCK
Browse files Browse the repository at this point in the history
Reviewed By: mkonicek

Differential Revision: D2874873

fb-gh-sync-id: 9feface8d9a18742e68206dbafb804de25f53ed8
shipit-source-id: 9feface8d9a18742e68206dbafb804de25f53ed8
  • Loading branch information
bestander authored and facebook-github-bot-7 committed Feb 26, 2016
1 parent 9d3d9df commit 5112a63
Show file tree
Hide file tree
Showing 20 changed files with 158 additions and 49 deletions.
3 changes: 3 additions & 0 deletions .buckconfig
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@

[maven_repositories]
central = https://repo1.maven.org/maven2

[alias]
movies = //Examples/Movies/android/app:app
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
43 changes: 43 additions & 0 deletions Examples/Movies/android/app/BUCK
Original file line number Diff line number Diff line change
@@ -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',
)
1 change: 1 addition & 0 deletions Examples/Movies/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
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 {
Expand Down
5 changes: 5 additions & 0 deletions ReactAndroid/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
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',
)
include_defs('//ReactAndroid/DEFS')

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',
# 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 = react_native_dep('third-party/android/support/v7/appcompat-orig:res-unpacker-cmd'),
package = 'com.facebook.react',
visibility = ['//ReactAndroid/...',],
)
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
],
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
Original file line number Diff line number Diff line change
@@ -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',
)
2 changes: 1 addition & 1 deletion ReactAndroid/src/main/third-party/android/support/v4/BUCK
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
android_prebuilt_aar(
name = 'lib-support-v4',
aar = ':lib-support-v4-binary-aar',
visibility = ['//ReactAndroid/...',],
visibility = ['PUBLIC',],
)

remote_file(
Expand Down
Original file line number Diff line number Diff line change
@@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
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
Expand All @@ -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])
2 changes: 1 addition & 1 deletion ReactAndroid/src/main/third-party/java/jsr-305/BUCK
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
prebuilt_jar(
name = 'jsr-305',
binary_jar = ':jsr305-binary-jar',
visibility = ['//ReactAndroid/...',],
visibility = ['PUBLIC'],
)

remote_file(
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 8 additions & 0 deletions keystores/BUCK
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
keystore(
name = 'debug',
store = 'debug.keystore',
properties = 'debug.keystore.properties',
visibility = [
'PUBLIC',
],
)
Binary file added keystores/debug.keystore
Binary file not shown.
4 changes: 4 additions & 0 deletions keystores/debug.keystore.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
key.store=debug.keystore
key.alias=androiddebugkey
key.store.password=android
key.alias.password=android

0 comments on commit 5112a63

Please sign in to comment.