Merge "Updated JNI interface."

This commit is contained in:
Paulo Casanova
2016-11-03 18:39:02 +00:00
committed by Android (Google) Code Review
4 changed files with 15 additions and 71 deletions

View File

@@ -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);
}

View File

@@ -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)

View File

@@ -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.
}

View File

@@ -7,6 +7,14 @@
#ifdef __cplusplus
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