Bug 1384312 - Support generating JNI wrappers under --with-gradle, r=nalexander

MozReview-Commit-ID: HECL60Ggeqn

--HG--
extra : rebase_source : da6e1711a7722d7e781a12305a5605b379afd843
This commit is contained in:
maliu 2017-10-11 15:37:40 -07:00
Родитель e83bd0bc4e
Коммит 7a95a6af9e
4 изменённых файлов: 70 добавлений и 8 удалений

Просмотреть файл

@ -355,6 +355,10 @@ android.applicationVariants.all { variant ->
}
}
android.applicationVariants.all { variant ->
configureVariantWithJNIWrappers(variant, "Fennec")
}
apply plugin: 'spoon'
spoon {

Просмотреть файл

@ -25,6 +25,8 @@ GARBAGE += \
GARBAGE_DIRS += classes db jars res sync services generated
gradle_dir := $(topobjdir)/gradle/build/mobile/android
# The bootclasspath is functionally identical to the classpath, but allows the
# classes given to redefine classes in core packages, such as java.lang.
# android.jar is here as it provides Android's definition of the Java Standard
@ -141,6 +143,7 @@ uniq = $(if $1,$(firstword $1) $(call uniq,$(filter-out $(firstword $1),$1)))
java_bundled_libs := $(call uniq,$(java_bundled_libs))
java_bundled_libs := $(subst $(NULL) ,:,$(strip $(java_bundled_libs)))
ifndef MOZ_BUILD_MOBILE_ANDROID_WITH_GRADLE
GECKOVIEW_JARS = \
constants.jar \
gecko-R.jar \
@ -166,8 +169,6 @@ ifdef MOZ_ANDROID_MMA
GECKOVIEW_JARS += gecko-thirdparty-leanplum_sdk.jar
endif
geckoview_jars_classpath := $(subst $(NULL) ,:,$(strip $(GECKOVIEW_JARS)))
FENNEC_JARS = \
gecko-browser.jar \
gecko-thirdparty.jar \
@ -182,6 +183,17 @@ ifdef MOZ_ANDROID_MLS_STUMBLER
FENNEC_JARS += ../stumbler/stumbler.jar
endif
else # MOZ_BUILD_MOBILE_ANDROID_WITH_GRADLE
GECKOVIEW_JARS := $(gradle_dir)/geckoview/intermediates/bundles/debug/classes.jar
FENNEC_JARS := $(gradle_dir)/app/intermediates/packaged/officialPhoton/debug/classes.jar
$(GECKOVIEW_JARS): .gradle.deps
$(FENNEC_JARS): .gradle.deps
endif # MOZ_BUILD_MOBILE_ANDROID_WITH_GRADLE
geckoview_jars_classpath := $(subst $(NULL) ,:,$(strip $(GECKOVIEW_JARS)))
# All the jars we're compiling from source. (not to be confused with
# java_bundled_libs, which holds the jars which we're including as binaries).
@ -228,22 +240,30 @@ endif # MOZ_INSTALL_TRACKING
library_jars := $(subst $(NULL) ,:,$(strip $(library_jars)))
gradle_dir := $(topobjdir)/gradle/build/mobile/android
ifdef MOZ_BUILD_MOBILE_ANDROID_WITH_GRADLE
.gradle.deps: .aapt.deps FORCE
@$(TOUCH) $@
$(topsrcdir)/mach gradle \
app:assembleOfficialPhotonDebug app:assembleOfficialPhotonDebugAndroidTest -x lint
geckoview:generateJNIWrappersForGeneratedRelease \
app:generateJNIWrappersForFennecOfficialPhotonDebug \
app:assembleOfficialPhotonDebug \
app:assembleOfficialPhotonDebugAndroidTest \
-x lint
classes.dex: .gradle.deps
$(REPORT_BUILD)
cp $(gradle_dir)/app/intermediates/transforms/dex/officialPhoton/debug/folders/1000/1f/main/classes.dex $@
GeneratedJNIWrappers.cpp GeneratedJNIWrappers.h GeneratedJNINatives.h : .gradle.deps
$(REPORT_BUILD)
FennecJNIWrappers.cpp FennecJNIWrappers.h FennecJNINatives.h: .gradle.deps
$(REPORT_BUILD)
else
classes.dex: .proguard.deps
$(REPORT_BUILD)
$(DX) --dex --output=classes.dex --force-jumbo jars-proguarded
endif
ifdef MOZ_DISABLE_PROGUARD
PROGUARD_PASSES=0
@ -328,6 +348,8 @@ FennecJNIWrappers.cpp: $(ANNOTATION_PROCESSOR_JAR_FILES) $(FENNEC_JARS)
org.mozilla.gecko.annotationProcessors.AnnotationProcessor \
Fennec $(FENNEC_JARS)
endif # MOZ_BUILD_MOBILE_ANDROID_WITH_GRADLE
include $(topsrcdir)/config/rules.mk
not_android_res_files := \
@ -536,7 +558,6 @@ endif
# GeneratedJNIWrappers.h and GeneratedJNINatives.h
# FennecJNIWrappers.cpp target also generates
# FennecJNIWrappers.h and FennecJNINatives.h
ifndef MOZ_BUILD_MOBILE_ANDROID_WITH_GRADLE
# List of build flags used by auto-generated JNI bindings (through the
# @BuildFlag annotation in Java). For example, add a "MOZ_FOO \" line to this
@ -586,11 +607,12 @@ libs:: FennecJNIWrappers.cpp
echo '* Repeat the build, and check in any changes. *' && \
echo '*****************************************************' && \
exit 1)
endif
libs:: classes.dex
$(INSTALL) classes.dex $(FINAL_TARGET)
ifndef MOZ_BUILD_MOBILE_ANDROID_WITH_GRADLE
# Generate Java binder interfaces from AIDL files.
GECKOVIEW_AIDLS = \
org/mozilla/gecko/IGeckoEditableChild.aidl \
@ -623,3 +645,5 @@ fennec_aidl_targets := $(addprefix $(fennec_aidl_target_path)/,$(patsubst %.aidl
$(fennec_aidl_targets): $(fennec_aidl_target_path)/%.java: $(fennec_aidl_src_path)/%.aidl
@echo "Processing AIDL: $< => $@"
$(AIDL) -p$(ANDROID_SDK)/framework.aidl -I$(fennec_aidl_src_path) -I$(geckoview_aidl_src_path) -o$(fennec_aidl_target_path) $<
endif # MOZ_BUILD_MOBILE_ANDROID_WITH_GRADLE

Просмотреть файл

@ -167,6 +167,10 @@ android.libraryVariants.all { variant ->
}
}
android.libraryVariants.all { variant ->
configureVariantWithJNIWrappers(variant, "Generated")
}
apply plugin: 'maven'
uploadArchives {

Просмотреть файл

@ -121,3 +121,33 @@ ext.configureVariantWithGeckoBinaries = { variant ->
android.sourceSets."${sourceSet}".assets.srcDir syncAssetsFromDistDir.destinationDir
android.sourceSets."${sourceSet}".jniLibs.srcDir syncLibsFromDistDir.destinationDir
}
ext.configureVariantWithJNIWrappers = { variant, module ->
def jarTask = tasks.findByName("jar${variant.name.capitalize()}Classes")
if (jarTask == null) {
jarTask = tasks.findByName("package${variant.name.capitalize()}JarArtifact")
}
if (jarTask == null) {
throw new GradleException("Jar task not found: \"jar${variant.name.capitalize()}Classes\"\t\"package${variant.name.capitalize()}JarArtifact\"" )
}
if (jarTask.outputs.files.size() != 1) {
throw new GradleException("Jar task output multiple files other than one single jar")
}
def wrapperTask = task("generateJNIWrappersFor${module}${variant.name.capitalize()}", type: JavaExec) {
classpath = variant.javaCompile.classpath
// Include android.jar.
classpath variant.javaCompile.options.bootClasspath
classpath "${topobjdir}/build/annotationProcessors/annotationProcessors.jar"
main = 'org.mozilla.gecko.annotationProcessors.AnnotationProcessor'
args module
args jarTask.outputs.files.iterator().next()
workingDir "${topobjdir}/mobile/android/base"
dependsOn jarTask
}
variant.assemble.dependsOn wrapperTask
}