Skip to content

Commit d71fe93

Browse files
committed
Sample Android application
This is a sample Android application that can be built with gradle and buck. It requires import_deps provided in facebook/buck#2706.
1 parent 3d714c0 commit d71fe93

34 files changed

+632
-0
lines changed

android/hello_world/.buckconfig

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[cache]
2+
mode = dir
3+
dir_max_size = 1GB
4+
5+
[android]
6+
target = android-32
7+
8+
[java]
9+
src_roots = /java/
10+
source_level = 8
11+
target_level = 8

android/hello_world/.gitignore

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
*.iml
2+
.gradle
3+
/local.properties
4+
/.idea/caches
5+
/.idea/libraries
6+
/.idea/modules.xml
7+
/.idea/workspace.xml
8+
/.idea/navEditor.xml
9+
/.idea/assetWizardSettings.xml
10+
.DS_Store
11+
/build
12+
/app/build
13+
/captures
14+
.externalNativeBuild
15+
.cxx
16+
local.properties
17+
18+
app/libs/*
19+
20+
# Buck
21+
/.buckd
22+
/buck-out
23+
/buck-cache
24+
25+
# Keystores
26+
# In Buck, all input files must live under the project root.
27+
# Therefore, you need to create the following files in this
28+
# project with your own keystore:
29+
keystore/debug.keystore
30+
# Most likely, you can use the standard debug keystore by running
31+
# the following:
32+
#
33+
# cp ~/.android/debug.keystore keystore/debug.keystore
34+
35+
third-party

android/hello_world/README.md

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
This is a sample Android app that can be built with gradle and buck.
2+
3+
How to build
4+
-------------
5+
6+
Define ANDROID_SDK environment variable
7+
```shell
8+
export ANDROID_SDK=/home/yourname/Android/Sdk
9+
```
10+
11+
Generate a keystore:
12+
```shell
13+
cd keystore
14+
keytool -genkey -keystore debug.keystore -alias my_alias \
15+
> -keyalg RSA -keysize 2048 -validity 10000
16+
```
17+
Update the keystore password in keystore/debug.keystore.properties.
18+
19+
Create a list of project dependencies
20+
```shell
21+
cd ..
22+
mkdir buck-out
23+
./gradlew -q :app:dependencies --configuration debugCompileClasspath > buck-out/deps.txt
24+
./gradlew -q :app:dependencies --configuration debugRuntimeClasspath >> buck-out/deps.txt
25+
./gradlew -q :app:dependencies --configuration debugAnnotationProcessorClasspath >> buck-out/deps.txt
26+
```
27+
28+
Use the import_deps tool to download dependencies and generate BUCK files.
29+
```shell
30+
cd ../import_deps
31+
./importdeps.py --gdeps /Users/mdzyuba/whatsapp/android/tools/buck/hello_world/buck-out/deps.txt --libs third-party
32+
cd ../hello_world
33+
mv ../import_deps/third-party .
34+
```
35+
Verify the generated third-party BUCK
36+
```shell
37+
buck targets //third-party:
38+
buck build //third-party:core
39+
```
40+
Start an Android emulator or device. It could be based on SDK Platform v21 - v32.
41+
42+
To build and install the app, run:
43+
```shell
44+
buck install //app:app
45+
```
46+
Then run Hello World app on the device.
47+
48+
Hare is a list of sample buck targets:
49+
```shell
50+
buck build //app:deps
51+
buck build //app:lib
52+
buck build //keystore:debug_keystore
53+
buck build //app:app
54+
```
55+

android/hello_world/app/BUCK

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
2+
android_library(
3+
name = "deps",
4+
exported_deps = [
5+
"//third-party/androidx/appcompat:appcompat",
6+
"//third-party/com/google/android/material:material",
7+
"//third-party/androidx/constraintlayout:constraintlayout"
8+
],
9+
visibility = ["PUBLIC"],
10+
)
11+
12+
android_build_config(
13+
name = "build_config",
14+
package = "com.example.helloworld",
15+
)
16+
17+
android_resource(
18+
name = 'res',
19+
res = 'src/main/res',
20+
package = 'com.example.helloworld',
21+
visibility = [
22+
"PUBLIC",
23+
],
24+
)
25+
26+
android_library(
27+
name = 'lib',
28+
srcs = glob(['src/main/java/**/*.java']),
29+
deps = [
30+
':res',
31+
':deps'
32+
],
33+
)
34+
35+
android_binary(
36+
name = 'app',
37+
aapt_mode = 'aapt2',
38+
manifest = 'src/main/AndroidManifest.xml',
39+
manifest_entries = {
40+
'version_code': 1,
41+
'version_name': '1.0',
42+
'min_sdk_version': 21,
43+
'target_sdk_version': 32
44+
},
45+
keystore = '//keystore:debug_keystore',
46+
deps = [
47+
':lib',
48+
':res',
49+
':deps',
50+
],
51+
)

android/hello_world/app/build.gradle

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
plugins {
2+
id 'com.android.application'
3+
}
4+
5+
android {
6+
compileSdk 32
7+
8+
defaultConfig {
9+
applicationId "com.example.helloworld"
10+
minSdk 21
11+
targetSdk 32
12+
versionCode 1
13+
versionName "1.0"
14+
15+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
16+
}
17+
18+
buildTypes {
19+
release {
20+
minifyEnabled false
21+
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
22+
}
23+
}
24+
compileOptions {
25+
sourceCompatibility JavaVersion.VERSION_1_8
26+
targetCompatibility JavaVersion.VERSION_1_8
27+
}
28+
}
29+
30+
dependencies {
31+
implementation 'androidx.appcompat:appcompat:1.4.1'
32+
implementation 'com.google.android.material:material:1.5.0'
33+
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
34+
testImplementation 'junit:junit:4.13.2'
35+
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
36+
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
37+
}
38+
39+
configurations {
40+
toCopy
41+
}
42+
43+
dependencies {
44+
toCopy 'androidx.appcompat:appcompat:1.4.1'
45+
toCopy 'com.google.android.material:material:1.5.0'
46+
toCopy 'androidx.constraintlayout:constraintlayout:2.1.3'
47+
}
48+
49+
task download(type: Copy) {
50+
from configurations.toCopy
51+
into 'libs'
52+
}
53+
54+
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.example.helloworld;
2+
3+
import static org.junit.Assert.*;
4+
5+
import android.content.Context;
6+
import androidx.test.ext.junit.runners.AndroidJUnit4;
7+
import androidx.test.platform.app.InstrumentationRegistry;
8+
import org.junit.Test;
9+
import org.junit.runner.RunWith;
10+
11+
/**
12+
* Instrumented test, which will execute on an Android device.
13+
*
14+
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
15+
*/
16+
@RunWith(AndroidJUnit4.class)
17+
public class ExampleInstrumentedTest {
18+
@Test
19+
public void useAppContext() {
20+
// Context of the app under test.
21+
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
22+
assertEquals("com.example.helloworld", appContext.getPackageName());
23+
}
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="com.example.helloworld">
4+
5+
<application
6+
android:allowBackup="true"
7+
android:icon="@mipmap/ic_launcher"
8+
android:label="@string/app_name"
9+
android:roundIcon="@mipmap/ic_launcher_round"
10+
android:supportsRtl="true"
11+
android:theme="@style/Theme.HelloWorld">
12+
<activity
13+
android:name=".MainActivity"
14+
android:exported="true">
15+
<intent-filter>
16+
<action android:name="android.intent.action.MAIN" />
17+
18+
<category android:name="android.intent.category.LAUNCHER" />
19+
</intent-filter>
20+
</activity>
21+
</application>
22+
23+
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.example.helloworld;
2+
3+
import android.os.Bundle;
4+
import androidx.appcompat.app.AppCompatActivity;
5+
6+
public class MainActivity extends AppCompatActivity {
7+
8+
@Override
9+
protected void onCreate(Bundle savedInstanceState) {
10+
super.onCreate(savedInstanceState);
11+
setContentView(R.layout.activity_main);
12+
}
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
xmlns:aapt="http://schemas.android.com/aapt"
3+
android:width="108dp"
4+
android:height="108dp"
5+
android:viewportWidth="108"
6+
android:viewportHeight="108">
7+
<path android:pathData="M31,63.928c0,0 6.4,-11 12.1,-13.1c7.2,-2.6 26,-1.4 26,-1.4l38.1,38.1L107,108.928l-32,-1L31,63.928z">
8+
<aapt:attr name="android:fillColor">
9+
<gradient
10+
android:endX="85.84757"
11+
android:endY="92.4963"
12+
android:startX="42.9492"
13+
android:startY="49.59793"
14+
android:type="linear">
15+
<item
16+
android:color="#44000000"
17+
android:offset="0.0" />
18+
<item
19+
android:color="#00000000"
20+
android:offset="1.0" />
21+
</gradient>
22+
</aapt:attr>
23+
</path>
24+
<path
25+
android:fillColor="#FFFFFF"
26+
android:fillType="nonZero"
27+
android:pathData="M65.3,45.828l3.8,-6.6c0.2,-0.4 0.1,-0.9 -0.3,-1.1c-0.4,-0.2 -0.9,-0.1 -1.1,0.3l-3.9,6.7c-6.3,-2.8 -13.4,-2.8 -19.7,0l-3.9,-6.7c-0.2,-0.4 -0.7,-0.5 -1.1,-0.3C38.8,38.328 38.7,38.828 38.9,39.228l3.8,6.6C36.2,49.428 31.7,56.028 31,63.928h46C76.3,56.028 71.8,49.428 65.3,45.828zM43.4,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2c-0.3,-0.7 -0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C45.3,56.528 44.5,57.328 43.4,57.328L43.4,57.328zM64.6,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2s-0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C66.5,56.528 65.6,57.328 64.6,57.328L64.6,57.328z"
28+
android:strokeWidth="1"
29+
android:strokeColor="#00000000" />
30+
</vector>

0 commit comments

Comments
 (0)