summaryrefslogtreecommitdiff
path: root/tools/aapt2/jni
diff options
context:
space:
mode:
authorPaulo Casanova <pasc@google.com>2016-11-01 14:50:46 +0000
committerPaulo Casanova <pasc@google.com>2016-11-03 10:14:42 +0000
commitb555b59f2e53c18e8bd10b51fd963c849eff2cef (patch)
tree96cb13336317741a3800508ed2d6973f069cece4 /tools/aapt2/jni
parent88dea2dd23e3df5f87826aa6e524233f37b17588 (diff)
Updated JNI interface.
Added new "ping" method used to detect if the shared library has already been loaded. Fixed a few bugs in the implementation (and now it works from the Java side). See http://ag/1590668 for the implementation on devtools. Test: Done on the tools side Change-Id: Ifa41073dc3b6ac69cdb9f77e655bf261c3b4c3d1
Diffstat (limited to 'tools/aapt2/jni')
-rw-r--r--tools/aapt2/jni/Aapt2.java44
-rw-r--r--tools/aapt2/jni/Makefile25
-rw-r--r--tools/aapt2/jni/aapt2_jni.cpp9
-rw-r--r--tools/aapt2/jni/com_android_tools_aapt2_Aapt2.h8
4 files changed, 15 insertions, 71 deletions
diff --git a/tools/aapt2/jni/Aapt2.java b/tools/aapt2/jni/Aapt2.java
deleted file mode 100644
index aed23de92fba..000000000000
--- a/tools/aapt2/jni/Aapt2.java
+++ /dev/null
@@ -1,44 +0,0 @@
-package com.android.tools.aapt2;
-
-import java.util.List;
-
-/**
- * {@code aapt2} JNI interface. To use the {@code aapt2} native interface, the
- * shared library must first be loaded and then a new instance of this class can
- * be used to access the library.
- */
-public class Aapt2 {
-
- /**
- * Invokes {@code aapt2} to perform resource compilation.
- *
- * @param arguments arguments for compilation (see {@code Compile.cpp})
- */
- public static void compile(List<String> arguments) {
- nativeCompile(arguments);
- }
-
- /**
- * Invokes {@code aapt2} to perform linking.
- *
- * @param arguments arguments for linking (see {@code Link.cpp})
- */
- public static void link(List<String> arguments) {
- nativeLink(arguments);
- }
-
- /**
- * JNI call.
- *
- * @param arguments arguments for compilation (see {@code Compile.cpp})
- */
- private static native void nativeCompile(List<String> arguments);
-
- /**
- * JNI call.
- *
- * @param arguments arguments for linking (see {@code Link.cpp})
- */
- private static native void nativeLink(List<String> arguments);
-}
-
diff --git a/tools/aapt2/jni/Makefile b/tools/aapt2/jni/Makefile
deleted file mode 100644
index a9e628f45ce5..000000000000
--- a/tools/aapt2/jni/Makefile
+++ /dev/null
@@ -1,25 +0,0 @@
-#
-# This Makefile will generate the JNI headers for the Aapt2 class.
-#
-
-AAPT2_PKG=com.android.tools.aapt2
-AAPT2_DIR=$(shell echo -n com/android/tools/aapt2 | tr . /)
-OUT=out
-OUT_CLASSES=$(OUT)/classes
-OUT_HEADERS=.
-
-AAPT2_JAVA=Aapt2.java
-AAPT2_CLASSES=$(OUT_CLASSES)/$(AAPT2_DIR)/Aapt2.class
-
-AAPT2_HEADERS=$(OUT_HEADERS)/Aapt2.h
-
-all: $(AAPT2_HEADERS)
-
-$(AAPT2_HEADERS): $(AAPT2_JAVA) $(AAPT2_CLASSES)
- mkdir -p $(OUT_HEADERS)
- $(JAVA_HOME)/bin/javah -d $(OUT_HEADERS) -cp $(OUT_CLASSES) $(AAPT2_PKG).Aapt2
-
-$(AAPT2_CLASSES): $(AAPT2_JAVA)
- mkdir -p $(OUT_CLASSES)
- javac -d $(OUT_CLASSES) $(AAPT2_JAVA)
-
diff --git a/tools/aapt2/jni/aapt2_jni.cpp b/tools/aapt2/jni/aapt2_jni.cpp
index 211ada8db078..a5e09a2c9d57 100644
--- a/tools/aapt2/jni/aapt2_jni.cpp
+++ b/tools/aapt2/jni/aapt2_jni.cpp
@@ -46,8 +46,8 @@ static std::vector<ScopedUtfChars> list_to_utfchars(JNIEnv *env, jobject obj) {
// Now, iterate all strings in the list
// (note: generic erasure means get() return an Object)
- jmethodID get_method_id =
- env->GetMethodID(list_cls, "get", "()Ljava/lang/Object;");
+ jmethodID get_method_id = env->GetMethodID(list_cls, "get", "(I)Ljava/lang/Object;");
+ CHECK(get_method_id != 0);
for (jint i = 0; i < size; i++) {
// Call get(i) to get the string in the ith position.
jobject string_obj_uncast = env->CallObjectMethod(obj, get_method_id, i);
@@ -92,3 +92,8 @@ JNIEXPORT void JNICALL Java_com_android_tools_aapt2_Aapt2_nativeLink(
std::vector<aapt::StringPiece> link_args = extract_pieces(link_args_jni);
aapt::Link(link_args);
}
+
+JNIEXPORT void JNICALL Java_com_android_tools_aapt2_Aapt2_ping(
+ JNIEnv *env, jclass aapt_obj) {
+ // This is just a dummy method to see if the library has been loaded.
+}
diff --git a/tools/aapt2/jni/com_android_tools_aapt2_Aapt2.h b/tools/aapt2/jni/com_android_tools_aapt2_Aapt2.h
index 443b98f2590d..26dc52db8695 100644
--- a/tools/aapt2/jni/com_android_tools_aapt2_Aapt2.h
+++ b/tools/aapt2/jni/com_android_tools_aapt2_Aapt2.h
@@ -9,6 +9,14 @@ extern "C" {
#endif
/*
* Class: com_android_tools_aapt2_Aapt2
+ * Method: ping
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL Java_com_android_tools_aapt2_Aapt2_ping
+ (JNIEnv *, jclass);
+
+/*
+ * Class: com_android_tools_aapt2_Aapt2
* Method: nativeCompile
* Signature: (Ljava/util/List;)V
*/