android compilation framework: a simple example.

This commit is contained in:
Vítor Santos Costa 2014-05-28 00:07:50 +01:00
parent 042b3e4343
commit 0d52c2d730
7 changed files with 114 additions and 35 deletions

View File

@ -0,0 +1,12 @@
# File: Android.mk
LOCAL_PATH := $(call my-dir)
NDK_TOOLCHAIN_VERSION := 4.8
include $(CLEAR_VARS)
LOCAL_LDLIBS += @abs_top_builddir@/libYap.a @abs_top_builddir@/yapi.o
LOCAL_MODULE := example
LOCAL_SRC_FILES := yap_wrap.cpp
LOCAL_C_INCLUDES := @abs_top_builddir@ @srcdir@/../../H @srcdir@/../../include @srcdir@/../../os @srcdir@/../../OPTYap @srcdir@/../../BEAM @srcdir@/../../CXX
LOCAL_CFLAGS := @DEFS@ -D_YAP_NOT_INSTALLED_=1
LOCAL_CPP_FEATURES := rtti
# LOCAL_ALLOW_UNDEFINED_SYMBOLS := true
include $(BUILD_SHARED_LIBRARY)

View File

@ -7,6 +7,7 @@ JAR=@JAR@
include ../Makefile.defs
DEFS=@DEFS@ -D_YAP_NOT_INSTALLED_=1 -DDESTDIR=\"$(DESTDIR)\"
YAP_EXTRAS=@YAP_EXTRAS@
srcdir=@srcdir@
CPPFLAGS=@CPPFLAGS@ -I../.. -I$(srcdir)/../../H -I$(srcdir)/../../include -I$(srcdir)/../../os -I$(srcdir)/../../OPTYap -I$(srcdir)/../../BEAM -I$(srcdir)/../../CXX
CXXFLAGS= @SHLIB_CXXFLAGS@ $(YAP_EXTRAS) $(DEFS) $(CPPFLAGS)
@ -34,16 +35,29 @@ java: jni/libyap.@SO@ java/yap.java
jni/libyap.@SO@: jni/yap_wrap.o
$(CXX) -shared $(LDSOFLAGS) -L ../.. -lYap -o $@ ../../yapi.o $< $(LIBS) @JPLLDFLAGS@ -L ../.. -lYap -lpthread
jni/yap_wrap.c: $(srcdir)/yap.i
jni/yap_wrap.cpp: $(srcdir)/yap.i
$(SWIG) -c++ -java -package pt.up.fc.dcc.yap -outdir java -o $@ $(DEFS) $(CPPFLAGS) -Wall $<
jni/yap_wrap.o: jni/yap_wrap.c
jni/yap_wrap.o: jni/yap_wrap.cpp
$(CXX) -c $(CXXFLAGS) @JPLCFLAGS@ $< -o $@
android: android/jni/yap_wrap.cpp
android/jni/yap_wrap.cpp: $(srcdir)/yap.i
android create project --target 1 --name SwigSimple --path ./android --activity SwigSimple --package org.swig.simple
( cd android ; mkdir -p jni;\
$(SWIG) -c++ -java -I$(srcdir)/../../CXX -package org.swig.simple -outdir src/org/swig/simple -o jni/yap_wrap.cpp $< ;\
cp $(srcdir)/android/SwigSimple.java src/org/swig/simple/ ;\
cp $(srcdir)/android/main.xml res/layout ;\
cp ../Android.mk jni ;\
ndk-build; \
ant debug \
)
R:
yap.i: $(srcdir)/../../include/YapInterface.h
yap.i: $(srcdir)/../../../../include/YapInterface.h
install:

View File

@ -0,0 +1,2 @@
# File: Application.mk
NDK_TOOLCHAIN_VERSION = 4.8

View File

@ -0,0 +1,55 @@
package org.swig.simple;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import android.widget.ScrollView;
import android.text.method.ScrollingMovementMethod;
public class SwigSimple extends Activity
{
TextView outputText = null;
ScrollView scroller = null;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
outputText = (TextView)findViewById(R.id.OutputText);
outputText.setText("Press 'Run' to start...\n");
outputText.setMovementMethod(new ScrollingMovementMethod());
scroller = (ScrollView)findViewById(R.id.Scroller);
}
public void onRunButtonClick(View view)
{
outputText.append("Started...\n");
nativeCall();
outputText.append("Finished!\n");
// Ensure scroll to end of text
scroller.post(new Runnable() {
public void run() {
scroller.fullScroll(ScrollView.FOCUS_DOWN);
}
});
}
/** Calls into C/C++ code */
public void nativeCall()
{
// YAPParams p = new YAPParams();
//YAPEngine t = new YAPEngine( p ); // TODO
}
/** static constructor */
static {
System.loadLibrary("example");
}
}

View File

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Button
android:id="@+id/RunButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Run..."
android:onClick="onRunButtonClick"
/>
<ScrollView
android:id="@+id/Scroller"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:id="@+id/OutputText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</ScrollView>
</LinearLayout>

View File

@ -24,13 +24,12 @@ if test "$PKG_SWIG" != ""; then
mkdir -p packages/swig/python
mkdir -p packages/swig/R
mkdir -p packages/swig/java
mkdir -p packages/swig/src
mkdir -p packages/swig/jni
mkdir -p packages/swig/fli
AC_SUBST(SWIG)
AC_SUBST(SWIG_TARGET)
AC_SUBST(PKG_SWIG)
AC_CONFIG_FILES([ packages/swig/Makefile packages/swig/jni/Android.mk ])
AC_CONFIG_FILES([ packages/swig/Makefile packages/swig/Android.mk ])
fi

View File

@ -1,29 +0,0 @@
#include <stdio.h>
#include <stdlib.h>
#include "YapInterface.h"
static void init_yap( void );
int yap_prove_string(char *s);
static int yap_on;
int
prove_string(char *s) {
if (!yap_on)
init_yap();
if (YAP_RunGoal(YAP_MkAtomTerm(YAP_LookupAtom(s)))) {
YAP_ShutdownGoal( TRUE );
return TRUE;
}
return FALSE;
}
static void
init_yap( void )
{
if (YAP_FastInit(NULL) == YAP_BOOT_ERROR)
exit(1);
yap_on = TRUE;
}