Skip to content

Commit

Permalink
Gradle for java library
Browse files Browse the repository at this point in the history
Summary: This builds the java bindings with gradle, and adds a script for Facebook employees to upload the generated artifacts to JCenter.

Reviewed By: emilsjolander

Differential Revision: D4597335

fbshipit-source-id: 4c01695a8638000a417bfb49deba4b9b9b4e114b
  • Loading branch information
Robert Spencer authored and facebook-github-bot committed Feb 23, 2017
1 parent 67717a7 commit 5519a73
Show file tree
Hide file tree
Showing 11 changed files with 264 additions and 14 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,6 @@ Pods/
# Carthage/Checkouts

Carthage/Build

# Gradle
.gradle
2 changes: 1 addition & 1 deletion android/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ include_defs('//YOGA_DEFS')

android_aar(
name = 'android',
manifest_skeleton = 'AndroidManifest.xml',
manifest_skeleton = 'src/main/AndroidManifest.xml',
deps = [
ANDROID_JAVA_TARGET,
ANDROID_RES_TARGET,
Expand Down
File renamed without changes.
26 changes: 13 additions & 13 deletions android/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,27 @@

<attr name="align_content" format="enum">
<enum name="auto" value="0"/>
<enum name="flex-start" value="1"/>
<enum name="flex_start" value="1"/>
<enum name="center" value="2"/>
<enum name="flex-end" value="3"/>
<enum name="flex_end" value="3"/>
<enum name="stretch" value="4"/>
<enum name="baseline" value="5"/>
</attr>

<attr name="align_items" format="enum">
<enum name="auto" value="0"/>
<enum name="flex-start" value="1"/>
<enum name="flex_start" value="1"/>
<enum name="center" value="2"/>
<enum name="flex-end" value="3"/>
<enum name="flex_end" value="3"/>
<enum name="stretch" value="4"/>
<enum name="baseline" value="5"/>
</attr>

<attr name="align_self" format="enum">
<enum name="auto" value="0"/>
<enum name="flex-start" value="1"/>
<enum name="flex_start" value="1"/>
<enum name="center" value="2"/>
<enum name="flex-end" value="3"/>
<enum name="flex_end" value="3"/>
<enum name="stretch" value="4"/>
<enum name="baseline" value="5"/>
</attr>
Expand Down Expand Up @@ -65,9 +65,9 @@

<attr name="flex_direction" format="enum">
<enum name="column" value="0"/>
<enum name="column-reverse" value="1"/>
<enum name="column_reverse" value="1"/>
<enum name="row" value="2"/>
<enum name="row-reverse" value="3"/>
<enum name="row_reverse" value="3"/>
</attr>

<attr name="flex_grow" format="float"/>
Expand All @@ -79,11 +79,11 @@
<attr name="height_percent" format="float"/>

<attr name="justify_content" format="enum">
<enum name="flex-start" value="0"/>
<enum name="flex_start" value="0"/>
<enum name="center" value="1"/>
<enum name="flex-end" value="2"/>
<enum name="space-between" value="3"/>
<enum name="space-around" value="4"/>
<enum name="flex_end" value="2"/>
<enum name="space_between" value="3"/>
<enum name="space_around" value="4"/>
</attr>

<attr name="margin_left" format="dimension"/>
Expand Down Expand Up @@ -178,7 +178,7 @@
<attr name="width_percent" format="float"/>

<attr name="wrap" format="enum">
<enum name="no-wrap" value="0"/>
<enum name="no_wrap" value="0"/>
<enum name="wrap" value="1"/>
</attr>
</declare-styleable>
Expand Down
31 changes: 31 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.2'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1'
classpath 'com.nabilhachicha:android-native-dependencies:0.1'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}

allprojects {
repositories {
flatDir {
dirs "${rootDir}/lib/jsr-305"
dirs "${rootDir}/lib/soloader"
dirs "${rootDir}/lib/appcompat"
dirs "${rootDir}/lib/android-support"
}
}
}

task clean(type: Delete) {
delete rootProject.buildDir
}
6 changes: 6 additions & 0 deletions java/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.facebook.yoga">

<application/>

</manifest>
148 changes: 148 additions & 0 deletions java/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
apply plugin: "com.jfrog.bintray"
apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'
apply plugin: 'maven-publish'

targetCompatibility = '1.7'
sourceCompatibility = '1.7'

version = '1.0.0'
group = 'com.facebook.yoga'

// We currently build the native libraries with buck and bundle them together
// at this point into the AAR
task buckBuildAndCopy(type: Exec) {
commandLine '../scripts/build_natives_for_gradle.sh'
}

android {
compileSdkVersion 19
buildToolsVersion "19.1.0"

defaultConfig {
minSdkVersion 15
targetSdkVersion 19
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}

sourceSets {
main {
java.srcDir 'com'
manifest.srcFile 'AndroidManifest.xml'
res.srcDirs = ['res']
jniLibs.srcDirs = ['build/buck-out/jniLibs']
}
}
}

preBuild.dependsOn buckBuildAndCopy

dependencies {
compile(name: 'jsr305')
compile(name: 'soloader-0.1.0', ext: 'aar')
}

task sourcesJar(type: Jar) {
from android.sourceSets.main.java.srcDirs
classifier = 'source'
}

task javadoc(type: Javadoc) {
failOnError false
source = android.sourceSets.main.java.sourceFiles
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
classpath += configurations.compile
}

task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from javadoc.destinationDir
}

ext {
bintrayRepo = 'maven'
bintrayUserOrg = 'facebook'
bintrayName = "com.facebook.yoga:yoga"
siteURL = "https://facebook.github.io/yoga/"
projectLicenses = {
license {
name 'BSD License'
url 'https://github.com/facebook/yoga/blob/master/LICENSE'
distribution 'repo'
}
}
}


def pomConfig = {
licenses {
// TODO Can we grab this from above?
license {
name 'BSD License'
url 'https://github.com/facebook/yoga/blob/master/LICENSE'
distribution 'repo'
}
}
}

publishing {
publications {
yoga(MavenPublication) {
groupId group
artifact(sourcesJar)
artifact(javadocJar)
pom.withXml {
def root = asNode()
root.appendNode('name', 'Yoga')
root.appendNode('url', siteURL)
root.children().last() + pomConfig
}
}
}
}

bintray {
user = getBintrayUsername()
key = getBintrayApiKey()
publications = ['yoga']
configurations = ['archives']
pkg {
repo = bintrayRepo
userOrg = bintrayUserOrg
name = bintrayName
dryRun = dryRunOnly()
licenses = projectLicenses
override = true
publish = true
publicDownloadNumbers = true
version {
name = version
released = new Date()
gpg {
sign = true
passphrase = getBintrayGpgPassword()
}
}
}
}


def getBintrayUsername() {
return hasProperty('bintrayUsername') ? property('bintrayUsername') : System.getenv('BINTRAY_USERNAME')
}

def getBintrayApiKey() {
return hasProperty('bintrayApiKey') ? property('bintrayApiKey') : System.getenv('BINTRAY_API_KEY')
}

def getBintrayGpgPassword() {
return hasProperty('bintrayGpgPassword') ? property('bintrayGpgPassword') : System.getenv('BINTRAY_GPG_PASSWORD')
}

def dryRunOnly() {
return hasProperty('dryRun') ? property('dryRun').toBoolean() : false
}
14 changes: 14 additions & 0 deletions java/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>

<!--
Copyright (c) 2014-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.
-->

<resources>
<string name="app_name">Yoga</string>
</resources>
16 changes: 16 additions & 0 deletions scripts/build_natives_for_gradle.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash

buck build //android:android

X86_DEST=build/buck-out/jniLibs/x86
ARMV7_DEST=build/buck-out/jniLibs/armabi-v7a

mkdir -p $X86_DEST
mkdir -p $ARMV7_DEST

cp ../buck-out/gen/java/jni#android-armv7,shared/libyoga.so $ARMV7_DEST
cp ../buck-out/gen/java/jni#android-x86,shared/libyoga.so $X86_DEST

cp ../buck-out/gen/yoga#android-armv7,shared/libyogacore.so $ARMV7_DEST
cp ../buck-out/gen/yoga#android-x86,shared/libyogacore.so $X86_DEST

30 changes: 30 additions & 0 deletions scripts/deploy_jcenter.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/bash
set -e

echo
echo -e "\033[1;34m** We'll need your Bintray credentials. If you don't remember them go to https://bintray.com/profile/edit\033[0m"

echo -e "\033[1;34m** [1/3] Please enter your Bintray username (probably not your email address): \033[0m"
read -r BINTRAY_USER
echo -e "\033[1;34m** [2/3] Please enter your Bintray API key: \033[0m"
read -r BINTRAY_KEY
echo -e "\033[1;34m** [3/3] Please enter your GPG passphrase: \033[0m"
read -r GPG_PASS

uploadcmd="gradle clean build bintrayUpload --info -PbintrayUsername='$BINTRAY_USER' -PbintrayApiKey='$BINTRAY_KEY' -PbintrayGpgPassword='$GPG_PASS'"

echo
echo -e "\033[1;34m** Dry run\033[0m"
(cd java; eval "$uploadcmd -PdryRun=true")

echo
echo -e "\033[1;34m** Are you happy to conintue?: [yN]\033[0m"
read -p "" -n 1 yn
case $yn in
[Yy]* ) ;;
* ) echo -e "\n\033[1;34m** Run $0 when you're ready to try again\033[0m" && exit;;
esac

echo
echo -e "\033[1;34m** Publishing\033[0m"
eval "$uploadcmd"
2 changes: 2 additions & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
include ':yoga'
project(':yoga').projectDir = file('java')

0 comments on commit 5519a73

Please sign in to comment.