Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
executable file 236 lines (208 sloc) 6.98 KB
#!/bin/sh
usage() {
cat << EOF
Usage: $0 <package> <dir>
EOF
exit 0
}
[ $# -ne 2 ] && usage
DIR="$2"
PKG="$1"
PKGDIR=$(echo $PKG | sed 's/\./\//g')
mkdir -p "$DIR"
cd "$DIR"
cat > .buckconfig << EOF
[alias]
app = //apps/$PKG:app
[java]
src_roots = /java/
[project]
# IntelliJ requires that every Android module have an
# AndroidManifest.xml file associated with it. In practice,
# most of this is unnecessary boilerplate, so we create one
# "shared" AndroidManifest.xml file that can be used as a default.
default_android_manifest = //res/AndroidManifest.xml
[android]
target = Google Inc.:Google APIs:21
[buildfile]
includes = //apps/DEFS
[download]
maven_repo = http://repo1.maven.org/maven2
in_build = true
EOF
mkdir -p "java/$PKGDIR"
mkdir -p "res/$PKGDIR"
mkdir -p "res/$PKGDIR/assets"
mkdir -p "res/$PKGDIR/res/values"
mkdir -p "apps/$PKG"
base64 -d > "apps/$PKG/debug.keystore" << EOF
/u3+7QAAAAIAAAABAAAAAQAIbXlfYWxpYXMAAAFAUNu5EAAABQAwggT8MA4GCisGAQQBKgIRAQEF
AASCBOicbcz1l1GShk4HbbhbFjCIkJdKS69PjxVu1DTXgqJW9gbhCRcsMT/+smMAFnLulUzJ3V6C
m7U2XBKh3Mezq+BtmWRYyAxU5ca+DzLHSN5ZMDDBnfhO0xaI+meCYTdEWy2M2saUoGRNiiaus0gc
hGWsi9HBL+UsKmxx/VrJqw5vyLquNcKRpbLtgIjMd18oFwADvF5c9LlObAA3a+UaEL7g8mhzadSP
oaFEcF5WC2kaf0xx3k0LGhFRpj+WX3k2AmeWqJnlI2ZVQ81sMrPs8o86413JYpJFROVZR/XqvjSa
xgQfknyELAQN7Hu7Fm24AmgCNIWtHb0yLABsD/IHZ6O0odeFtvHxnO/US4fWbIh1FHnTa76rrZoJ
x8eKs81CM4Pj0RNtNoC+Q3T6L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AAOCAQEABLnGuSWylWUmqrzX0OQfxYVMl/IAmIN55dGf
WH7LPnS9vt8HvIHrVMiwSNplxm4me4ZBL/5+WnodOPPbFdErAv9XiUnyiYw9cqSiQx6XO3adcOYP
ZdGQxFZcdNWAwWuKprgXjxXtEUzIkP7cZv1UaQ6MUzm+FItlnLI2daFt6cc+KzcQSPsU4Elvack8
+voXDcxJEt+ZcTfJk2qq0diDH6Iw9jfCBB3cL97aDwtDESBquYaTAUwFklmcxDFItf/HAM1EC4ph
F94vZ2HmfNRQIsNPMiLAxZRdC6PEFhBDTfyjDrpN/nwB5ce/ABZ9li6MZqgSf7VwRR3ThXWZGpT6
cnAZofppepsIbk4mwNLDMfoiLHMi
EOF
cat > "apps/$PKG/debug.keystore.properties" << EOF
key.alias=my_alias
key.store.password=android
key.alias.password=android
EOF
cat > "apps/DEFS" << EOF
import urllib
#
# This is a very quick-n-dirty bucklet for maven packages (jar and aar)
#
def mavensha1(group, name, version, ar):
try:
link = 'http://repo1.maven.org/maven2/{0}/{1}/{2}/{1}-{2}.{3}.sha1'.format(group.replace('.', '/'), name, version, ar)
f = urllib.urlopen(link)
cksum = f.read()
int(cksum, 16) # will throw an error if cksum is not a hexadecimal string
return cksum
except ValueError:
return None
def maven(pkg):
group, name, version = pkg.split(':', 3)
for ar in ['aar', 'jar']:
cksum = mavensha1(group, name, version, ar)
if cksum != None:
if ar == 'aar':
android_prebuilt_aar(
name = name,
aar = ':'+name+'-maven',
)
remote_file(
name = name + '-maven',
sha1 = cksum,
url = 'mvn:' + group + ':' + name + ':' + ar + ':' + version,
out = name + '.' + ar,
)
else:
prebuilt_jar(
name = name,
binary_jar = ':' + name + '-maven',
)
remote_file(
name = name,
sha1 = cksum,
url = 'mvn:' + group + ':' + name + ':' + ar + ':' + version,
out = name + '.' + ar,
)
return
print('Not found ' + pkg)
EOF
cat > "apps/$PKG/BUCK" << EOF
android_binary(
name = 'app',
manifest = 'AndroidManifest.xml',
keystore = ':debug_keystore',
deps = [
'//java/$PKGDIR:app',
'//res/$PKGDIR:res',
],
)
keystore(
name = 'debug_keystore',
store = 'debug.keystore',
properties = 'debug.keystore.properties',
)
project_config(src_target = ':app')
EOF
cat > "apps/$PKG/AndroidManifest.xml" << EOF
<?xml version='1.0' encoding='utf-8'?>
<manifest xmlns:android='http://schemas.android.com/apk/res/android'
package='$PKG'>
<application
android:label='@string/app_name'
android:hardwareAccelerated='true'>
<activity android:name='.MainActivity'>
<intent-filter>
<action android:name='android.intent.action.MAIN' />
<category android:name='android.intent.category.LAUNCHER' />
</intent-filter>
</activity>
</application>
</manifest>
EOF
cat > "java/$PKGDIR/BUCK" << EOF
android_library(
name = 'app',
srcs = glob(['*.java']),
visibility = [ 'PUBLIC' ],
deps = [
# Uncomment this if you want to include otto as a maven dependency
# ':otto',
],
)
# Example of maven dependencies
#maven('com.squareup:otto:1.3.7')
project_config(src_target = ':app')
EOF
cat > "java/$PKGDIR/MainActivity.java" << EOF
package $PKG;
import android.app.Activity;
import android.os.Bundle;
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle b) {
super.onCreate(b);
}
}
EOF
cat > "res/AndroidManifest.xml" << EOF
<?xml version="1.0" encoding="utf-8"?>
<manifest package="$PKG"/>
EOF
cat > "res/$PKGDIR/res/values/strings.xml" << EOF
<?xml version='1.0' encoding='utf-8' ?>
<resources>
<string name='app_name'>$(basename $PKGDIR)</string>
</resources>
EOF
cat > "res/$PKGDIR/BUCK" << EOF
android_resource(
name = 'res',
res = 'res',
assets = 'assets',
package = '$PKG',
visibility = [
'//apps/$PKG:',
],
)
project_config(src_target = ':res', src_roots = None)
EOF