From: Marcus Comstedt Date: Wed, 7 Dec 2016 19:25:45 +0000 (+0100) Subject: Bundle Java bindings into an AAR for ease of use X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=711d21ce5fbc3b96acee1aad8ad2cb94b5b0f19e;p=sigrok-androidutils.git Bundle Java bindings into an AAR for ease of use --- diff --git a/.gitignore b/.gitignore index 0d9b94f..3b15d21 100644 --- a/.gitignore +++ b/.gitignore @@ -14,11 +14,14 @@ Makefile.in /ltmain.sh /missing /ar-lib +/jni/ *.jar *.class *.o *.lo *.la +*.aar +*.pom .deps/ .libs/ .dirstamp diff --git a/AndroidManifest.xml.in b/AndroidManifest.xml.in new file mode 100644 index 0000000..1256ec4 --- /dev/null +++ b/AndroidManifest.xml.in @@ -0,0 +1,34 @@ + + + + + + + + + + + diff --git a/Makefile.am b/Makefile.am index 4df180c..1926acf 100644 --- a/Makefile.am +++ b/Makefile.am @@ -38,11 +38,20 @@ dist_pkgdata_DATA = device_filter.xml jardir = $(prefix)/jar jar_DATA = $(UTILS_JAR) $(ANTTASKS_JAR) +mvndir = $(prefix)/.m2/repository/org/sigrok/sigrok-core-android/$(BINDINGS_VERSION) +mvn_DATA = $(SIGROK_CORE_AAR) $(SIGROK_CORE_POM) + UTILS_JAR = sigrok-androidutils.jar ANTTASKS_JAR = ant/sigrok-androidutils-anttasks.jar -ANTFLAGS = -Dandroid.sdk=$(ANDROID_SDK) -Dandroid.platform=$(ANDROID_PLATFORM) +BINDINGS_VERSION = $(LIBSIGROKCXX_VERSION) + +SIGROK_CORE_AAR = sigrok-core-android-$(BINDINGS_VERSION).aar +SIGROK_CORE_POM = sigrok-core-android-$(BINDINGS_VERSION).pom + +ANTFLAGS = -Dandroid.sdk=$(ANDROID_SDK) -Dandroid.platform=$(ANDROID_PLATFORM) \ + -Dprefix=$(prefix) -Dbindings.version=$(BINDINGS_VERSION) EXTRA_DIST = build.xml src ant/src ant/resources @@ -52,9 +61,16 @@ $(UTILS_JAR): always $(ANTTASKS_JAR): always $(AM_V_GEN)ant -S -q anttasks +$(SIGROK_CORE_AAR): always $(UTILS_JAR) $(ANTTASKS_JAR) $(lib_LTLIBRARIES) + $(AM_V_GEN)ant -S -q $(ANTFLAGS) aar + +$(SIGROK_CORE_POM): always + $(AM_V_GEN)ant -S -q $(ANTFLAGS) pom + clean-local: - -rm -rf build ant/build + -rm -rf build ant/build jni -rm -f $(UTILS_JAR) $(ANTTASKS_JAR) + -rm -f $(SIGROK_CORE_AAR) $(SIGROK_CORE_POM) classes.jar .PHONY: always diff --git a/ant/src/org/sigrok/androidutils/ant/CopyLibsTask.java b/ant/src/org/sigrok/androidutils/ant/CopyLibsTask.java index d9b8cef..38e5e0d 100644 --- a/ant/src/org/sigrok/androidutils/ant/CopyLibsTask.java +++ b/ant/src/org/sigrok/androidutils/ant/CopyLibsTask.java @@ -35,6 +35,7 @@ import java.util.Queue; import java.util.TreeSet; import java.util.Vector; import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.DynamicAttribute; import org.apache.tools.ant.Task; import org.apache.tools.ant.types.FileSet; import org.apache.tools.ant.types.PatternSet; @@ -43,7 +44,7 @@ import org.apache.tools.ant.types.ResourceCollection; import org.apache.tools.ant.types.resources.FileProvider; import org.apache.tools.ant.types.selectors.SelectorUtils; -public class CopyLibsTask extends Task +public class CopyLibsTask extends Task implements DynamicAttribute { private static final HashMap blacklist; @@ -208,7 +209,7 @@ public class CopyLibsTask extends Task protected File getDestName(File dest) { - File d = new File(dest, subdir); + File d = (subdir == null? dest : new File(dest, subdir)); File f = new File(d, destname); return f; } @@ -476,12 +477,21 @@ public class CopyLibsTask extends Task protected Vector rcs = new Vector(); protected PatternSet patterns = new PatternSet(); protected String property = null; + protected Vector rpath = new Vector(); public void setTodir(File destDir) { this.destDir = destDir; } + public void setDynamicAttribute(String name, String value) + { + if ("rpath-link".equals(name)) + this.rpath.add(value); + else + throw new BuildException("copylibs doesn't support the \"" + name + "\" attribute"); + } + public void addFileset(FileSet set) { add(set); @@ -528,8 +538,10 @@ public class CopyLibsTask extends Task } Integer m = new Integer(l.elf.header.e_machine); Worker w = workers.get(m); - if (w == null) + if (w == null) { workers.put(m, (w = new Worker(m.intValue()))); + w.addRpath(rpath); + } w.addWork(l); } } diff --git a/build.xml b/build.xml index b76ef35..04496cd 100644 --- a/build.xml +++ b/build.xml @@ -21,10 +21,12 @@ + + + classpath="${android.sdk}/platforms/${android.platform}/android.jar"/> @@ -39,4 +41,74 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ${bundled_libs} + +]]> + + + + + + + + + 4.0.0 + org.sigrok + sigrok-core-android + ${bindings.version} + aar + +]]> + + diff --git a/configure.ac b/configure.ac index b95296e..7d1bce8 100644 --- a/configure.ac +++ b/configure.ac @@ -42,7 +42,12 @@ LT_INIT AC_PROG_CXX AM_PROG_CC_C_O +PKG_CHECK_MODULES([LIBSIGROKCXX], [libsigrokcxx], [ + LIBSIGROKCXX_VERSION=`$PKG_CONFIG --modversion "libsigrokcxx" 2>&AS_MESSAGE_LOG_FD` +]) + AC_SUBST([ANDROID_SDK]) AC_SUBST([ANDROID_PLATFORM]) +AC_SUBST([LIBSIGROKCXX_VERSION]) AC_OUTPUT([Makefile lib/libsigrokandroidutils.pc]) diff --git a/src/org/sigrok/androidutils/SigrokApplication.java b/src/org/sigrok/androidutils/SigrokApplication.java new file mode 100644 index 0000000..5a68792 --- /dev/null +++ b/src/org/sigrok/androidutils/SigrokApplication.java @@ -0,0 +1,66 @@ +/* + * This file is part of the sigrok-androidutils project. + * + * Copyright (C) 2016 Marcus Comstedt + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package org.sigrok.androidutils; + +import android.app.Application; +import android.content.Context; +import android.content.pm.ApplicationInfo; +import android.content.pm.PackageManager; +import android.util.Log; + +public class SigrokApplication extends Application { + + private static final String JNI_LIBS_RESOURCE_ID_META = + "org.sigrok.androidutils.jni_libs_resource_id"; + + public SigrokApplication() + { + } + + public static void initSigrok(Context context) + { + ApplicationInfo appInfo = context.getApplicationInfo(); + Environment.initEnvironment(appInfo.sourceDir); + UsbHelper.setContext(context); + try { + appInfo = context.getPackageManager(). + getApplicationInfo(context.getPackageName(), + PackageManager.GET_META_DATA); + } catch (PackageManager.NameNotFoundException exc) { + } + if (appInfo.metaData != null && + appInfo.metaData.containsKey(JNI_LIBS_RESOURCE_ID_META)) { + int resId = appInfo.metaData.getInt(JNI_LIBS_RESOURCE_ID_META); + String[] libs = context.getResources().getStringArray(resId); + int numLibs = libs.length; + for (int i = 0; i < numLibs; i++) { + String libName = libs[i]; + System.loadLibrary(libName); + } + } + } + + @Override + public void onCreate() + { + super.onCreate(); + initSigrok(getApplicationContext()); + } +}