From cee2f22c50471f1e3a4593069f45b0cf5650b674 Mon Sep 17 00:00:00 2001 From: Nick Alexander Date: Wed, 28 Oct 2015 16:01:23 -0700 Subject: [PATCH] Bug 1219846 - Part 1: Add 'app' Gradle project in srcdir. r=me DONTBUILD NPOTB --- mobile/android/app/build.gradle | 163 ++++++++++++++++++++++++++++++++ settings.gradle | 2 +- 2 files changed, 164 insertions(+), 1 deletion(-) create mode 100644 mobile/android/app/build.gradle diff --git a/mobile/android/app/build.gradle b/mobile/android/app/build.gradle new file mode 100644 index 00000000000..480a1b6573c --- /dev/null +++ b/mobile/android/app/build.gradle @@ -0,0 +1,163 @@ +buildDir "${topobjdir}/gradle/build/mobile/android/app" + +apply plugin: 'com.android.application' + +android { + compileSdkVersion 23 + buildToolsVersion "23.0.1" + + defaultConfig { + targetSdkVersion 22 + minSdkVersion 9 + applicationId mozconfig.substs.ANDROID_PACKAGE_NAME + testApplicationId 'org.mozilla.roboexample.test' + testInstrumentationRunner 'org.mozilla.gecko.FennecInstrumentationTestRunner' + } + + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_7 + targetCompatibility JavaVersion.VERSION_1_7 + } + + lintOptions { + abortOnError false + } + + buildTypes { + release { + minifyEnabled true + proguardFile "${topsrcdir}/mobile/android/config/proguard/proguard.cfg" + } + } + + sourceSets { + main { + manifest.srcFile "${topobjdir}/mobile/android/base/AndroidManifest.xml" + } + + androidTest { + manifest.srcFile "${topobjdir}/build/mobile/robocop/AndroidManifest.xml" + java { + srcDir "${topsrcdir}/mobile/android/tests/browser/robocop/src" + srcDir "${topsrcdir}/mobile/android/tests/background/junit3/src" + srcDir "${topsrcdir}/mobile/android/tests/browser/junit3/src" + srcDir "${topsrcdir}/mobile/android/tests/javaddons/src" + } + res { + srcDir "${topsrcdir}/build/mobile/robocop/res" + } + assets { + srcDir "${topsrcdir}/mobile/android/tests/browser/robocop/assets" + } + } + } +} + +dependencies { + compile project(':base') + compile project(':omnijar') + // Including the Robotium JAR directly can cause issues with dexing. + androidTestCompile 'com.jayway.android.robotium:robotium-solo:4.3.1' +} + +task syncOmnijarFromDistDir(type: Sync) { + into("${project.buildDir}/generated/omnijar") + from("${topobjdir}/dist/fennec/assets") { + include 'omni.ja' + } +} + +task checkLibsExistInDistDir<< { + if (syncLibsFromDistDir.source.empty) { + throw new GradleException("Required JNI libraries not found in ${topobjdir}/dist/fennec/lib. Have you built and packaged?") + } +} + +task syncLibsFromDistDir(type: Sync, dependsOn: checkLibsExistInDistDir) { + into("${project.buildDir}/generated/jniLibs") + from("${topobjdir}/dist/fennec/lib") +} + +task checkAssetsExistInDistDir<< { + if (syncAssetsFromDistDir.source.empty) { + throw new GradleException("Required assets not found in ${topobjdir}/dist/fennec/assets. Have you built and packaged?") + } +} + +task syncAssetsFromDistDir(type: Sync, dependsOn: checkAssetsExistInDistDir) { + into("${project.buildDir}/generated/assets") + from("${topobjdir}/dist/fennec/assets") { + exclude 'omni.ja' + } +} + +/** + * We want to expose the JSM files and chrome content to IDEs; the omnijar + * project does this. In addition, the :omnijar:buildOmnijar task builds a new + * omni.ja (directly into the object directory). + * + * The task dependency is: :generateDebugAssets -> :omnijar:buildOmnijar. + * + * One might expect that we could do this all in the omnijar project, but there + * appears to be a bug (which I have not fully isolated) where-by debug-only + * assets in a library (.aar file) are ignored in favor of release assets. This + * means we would have to insert the omni.ja into the omnijar project's release + * assets, which is altogether confusing. + */ +android.applicationVariants.all { variant -> + // We only insert omni.ja and the .so libraries into debug builds. + def name = variant.buildType.name + if (!name.contains(com.android.builder.core.BuilderConstants.DEBUG)) { + return + } + + def buildOmnijarTask = project(':omnijar').tasks.getByName('buildOmnijar') + syncOmnijarFromDistDir.dependsOn buildOmnijarTask + def generateAssetsTask = tasks.findByName("generate${name.capitalize()}Assets") + generateAssetsTask.dependsOn syncOmnijarFromDistDir + generateAssetsTask.dependsOn syncLibsFromDistDir + generateAssetsTask.dependsOn syncAssetsFromDistDir + + android.sourceSets.debug.assets.srcDir syncOmnijarFromDistDir.destinationDir + android.sourceSets.debug.assets.srcDir syncAssetsFromDistDir.destinationDir + android.sourceSets.debug.jniLibs.srcDir syncLibsFromDistDir.destinationDir +} + +apply plugin: 'spoon' + +spoon { + // For now, let's be verbose. + debug = true + // It's not helpful to pass when we don't have a device connected. + failIfNoDeviceConnected = true + + def spoonPackageName + if (gradle.startParameter.taskNames.contains('runBrowserTests')) { + spoonPackageName = 'org.mozilla.tests.browser.junit3' + } + if (gradle.startParameter.taskNames.contains('runBackgroundTests')) { + spoonPackageName = 'org.mozilla.gecko.background' + } + if (project.hasProperty('spoonPackageName')) { + // Command line overrides everything. + spoonPackageName = project.spoonPackageName + } + if (spoonPackageName) { + instrumentationArgs = ['-e', "package=${spoonPackageName}".toString()] + } +} + +// See discussion at https://github.com/stanfy/spoon-gradle-plugin/issues/9. +afterEvaluate { + tasks["spoon${android.testBuildType.capitalize()}AndroidTest"].outputs.upToDateWhen { false } + + // This is an awkward way to define different sets of instrumentation tests. + // The task name itself is fished at runtime and the package name configured + // in the spoon configuration. + task runBrowserTests { + dependsOn tasks["spoonDebugAndroidTest"] + } + task runBackgroundTests { + dependsOn tasks["spoonDebugAndroidTest"] + } +} diff --git a/settings.gradle b/settings.gradle index dc54003785f..ec4af288150 100644 --- a/settings.gradle +++ b/settings.gradle @@ -27,7 +27,7 @@ include ':omnijar' include ':thirdparty' def gradleRoot = new File("${json.topobjdir}/mobile/android/gradle") -project(':app').projectDir = new File(gradleRoot, 'app') +project(':app').projectDir = new File("${json.topsrcdir}/mobile/android/app") project(':base').projectDir = new File(gradleRoot, 'base') project(':omnijar').projectDir = new File(gradleRoot, 'omnijar') project(':thirdparty').projectDir = new File("${json.topsrcdir}/mobile/android/thirdparty")