Android project template - #119

This commit is contained in:
Vadim Lopatin 2016-04-21 16:18:03 +03:00
parent 245c821822
commit 587b5f713e
10 changed files with 168 additions and 7 deletions

View File

@ -0,0 +1,38 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- BEGIN_INCLUDE(manifest) -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.dlangui.example"
android:versionCode="1"
android:versionName="1.0">
<!-- This is the platform API where NativeActivity was introduced. -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-sdk android:minSdkVersion="19" android:targetSdkVersion="19"/>
<!-- This .apk has no Java code itself, so set hasCode to false. -->
<application android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
android:hasCode="false">
<!-- Our activity is the built-in NativeActivity framework class.
This will take care of integrating with our NDK code. -->
<activity android:name="android.app.NativeActivity"
android:label="@string/app_name"
android:configChanges="orientation|keyboardHidden|locale|screenSize|screenLayout|locale"
android:launchMode="singleTask"
android:windowSoftInputMode="stateHidden"
android:screenOrientation="portrait"
>
<!-- Tell NativeActivity the name of or .so -->
<meta-data android:name="android.app.lib_name"
android:value="dlangui-activity" />
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
<!-- END_INCLUDE(manifest) -->

View File

@ -0,0 +1,36 @@
This is template for DlangUI Android project.
============================================
Copy this directory to some DlangUI project's directory to allow Android builds.
Currently only armv7a architecture is supported.
Probably you will want to change android package name in AndroidManifest.xml and application display name in res/values/strings.xml
Modify android_app.mk, android_build_config.mk
android_app.mk
==============
Update LOCAL_SRC_FILES to include all your project's files.
android_build_config.mk
=======================
Update paths to Android NDK, SDK, DlangUI source directory.
Default values:
export DLANGUI_DIR=$HOME/src/d/dlangui
export NDK=$HOME/android-ndk-r11c
export SDK=$HOME/android-sdk-linux
export LDC=$HOME/ldc2-android-arm-0.17.0-alpha2-linux-x86_64
export NDK_ARCH=x86_64
Use LDC cross compiler for armv7a build according instructions
https://wiki.dlang.org/Build_LDC_for_Android#Build_a_sample_OpenGL_Android_app_ported_to_D

View File

@ -0,0 +1,15 @@
# List application source files here
# application library name ("app" -> libapp.so)
LOCAL_MODULE=dlangui-activity
# applicatino source files: put list of your source files here
LOCAL_SRC_FILES="\
../src/app.d \
"
# Additional libraries to link
LOCAL_LDLIBS=""
# Android SDK target
ANDROID_TARGET="android-19"

View File

@ -0,0 +1,11 @@
#!/bin/sh
#=========================================================================
# Modify this file to specify DLANGUI, Android NDK, SDK and LDC2 locations.
export DLANGUI_DIR=$HOME/src/d/dlangui
export NDK=$HOME/android-ndk-r11c
export SDK=$HOME/android-sdk-linux
export LDC=$HOME/ldc2-android-arm-0.17.0-alpha2-linux-x86_64
export NDK_ARCH=x86_64
export JAVA_HOME=/usr/lib/jvm/java-8-oracle/

View File

@ -0,0 +1,42 @@
#!/bin/sh
# load settings for paths
. ./android_build_config.mk
echo ""
echo "===================================="
echo "DlangUI Build for Android native app"
echo "===================================="
echo "DLANGUI_DIR: $DLANGUI_DIR"
echo "NDK: $NDK"
echo "SDK: $SDK"
echo "LDC: $LDC"
# dlangui sources
. $DLANGUI_DIR/android/dlangui_source_files.mk
# local application sources
. ./android_app.mk
warn () {
echo "$0:" "$@" >&2
}
die () {
rc=$1
shift
warn "$@"
exit $rc
}
# LDC2 arm build
. $DLANGUI_DIR/android/android_ldc_armv7a.mk
echo "Updating ant project..."
#=========================================================
$SDK/tools/android update project -p . -s --target $ANDROID_TARGET || die 3 "Android Project update is failed"
echo "Building APK..."
#=========================================================
ant debug || die 4 "Android APK creation is failed"
echo "Successful."

View File

@ -0,0 +1,4 @@
#!/bin/sh
. ./android_build_config.mk
$SDK/platform-tools/adb install -r bin/NativeActivity-debug.apk

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">DlangUI App</string>
</resources>

View File

@ -0,0 +1,4 @@
#!/bin/sh
. ./android_build_config.mk
$SDK/platform-tools/adb logcat | less

View File

@ -29,10 +29,10 @@ extern (C) int UIAppMain(string[] args) {
colCount: 2
layoutWidth: fill
TextWidget { text: "param 1" }
EditLine { id: edit1; text: "some text"; layoutWidth: fill }
EditLine { id: edit1; text: "some text"; layoutWidth: fill; margins: 3pt }
TextWidget { text: "param 2" }
EditLine { id: edit2; text: "some text for param2"; layoutWidth: fill }
TextWidget { text: "some radio buttons" }
EditLine { id: edit2; text: "some text for param2"; layoutWidth: fill; margins: 3pt }
TextWidget { text: "Radio buttons" }
// arrange some radio buttons vertically
VerticalLayout {
layoutWidth: fill
@ -40,11 +40,15 @@ extern (C) int UIAppMain(string[] args) {
RadioButton { id: rb2; text: "Item 2" }
RadioButton { id: rb3; text: "Item 3" }
}
TextWidget { text: "Switch:" }
SwitchWidget { checked: true }
TextWidget { text: "and checkboxes" }
TextWidget { text: "Switches:" }
VerticalLayout {
SwitchWidget { checked: true }
SwitchWidget { checked: false }
SwitchWidget { checked: true; enabled: false }
}
TextWidget { text: "Checkboxes:" }
// arrange some checkboxes horizontally
HorizontalLayout {
VerticalLayout {
layoutWidth: fill
CheckBox { id: cb1; text: "checkbox 1" }
CheckBox { id: cb2; text: "checkbox 2" }

View File

@ -441,6 +441,9 @@ class AndroidPlatform : Platform {
break;
}
}
if (_windows.length == 0) {
_appstate.destroyRequested = true;
}
}
@property AndroidWindow activeWindow() {