summaryrefslogtreecommitdiffstats
path: root/mobile/android/geckoview/build.gradle
blob: cc46530cbb4cb84da28d9fb041fda511780284d6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
buildDir "${topobjdir}/gradle/build/mobile/android/geckoview"

apply plugin: 'android-sdk-manager' // Must come before 'com.android.*'.
apply plugin: 'com.android.library'

def VERSION_NAME = '0.0.1'

android {
    compileSdkVersion 23
    buildToolsVersion mozconfig.substs.ANDROID_BUILD_TOOLS_VERSION

    defaultConfig {
        // TODO: version GeckoView explicitly.  We'd like to avoid
        // mozconfig.substs.ANDROID_VERSION_CODE, which won't be intuitive to
        // consumer (and advances very quickly on pre-release channels).
        versionCode 1
        versionName VERSION_NAME
        targetSdkVersion 23
        minSdkVersion 15
        consumerProguardFiles 'proguard-rules.txt' 
    }

    buildTypes {
        withGeckoBinaries {
            initWith release
        }
        withoutGeckoBinaries { // For clarity and consistency throughout the tree.
            initWith release
        }
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }

    dexOptions {
        javaMaxHeapSize "2g"
    }

    lintOptions {
        abortOnError false
    }

    sourceSets {
        main {
            java {
                srcDir "${topsrcdir}/mobile/android/geckoview/src/thirdparty/java"

                // TODO: support WebRTC.
                // if (mozconfig.substs.MOZ_WEBRTC) {
                //     srcDir "${topsrcdir}/media/webrtc/trunk/webrtc/modules/audio_device/android/java/src"
                //     srcDir "${topsrcdir}/media/webrtc/trunk/webrtc/modules/video_capture/android/java/src"
                //     srcDir "${topsrcdir}/media/webrtc/trunk/webrtc/modules/video_render/android/java/src"
                // }

                // TODO: don't use AppConstants.
                srcDir "${project.buildDir}/generated/source/preprocessed_code" // See syncPreprocessedCode.
            }

            assets {
            }
        }
    }
}

dependencies {
    compile "com.android.support:support-v4:${mozconfig.substs.ANDROID_SUPPORT_LIBRARY_VERSION}"
}

task syncPreprocessedCode(type: Sync, dependsOn: rootProject.generateCodeAndResources) {
    into("${project.buildDir}/generated/source/preprocessed_code")
    from("${topobjdir}/mobile/android/base/generated/preprocessed") {
        // AdjustConstants is included in the main app project.
        exclude '**/AdjustConstants.java'
    }
}

apply from: "${topsrcdir}/mobile/android/gradle/with_gecko_binaries.gradle"

android.libraryVariants.all { variant ->
    variant.preBuild.dependsOn syncPreprocessedCode

    // Like 'debug', 'release', or 'withGeckoBinaries'.
    def buildType = variant.buildType.name

    // It would be most natural for :geckoview to always include the Gecko
    // binaries, but that's difficult; see the notes in
    // mobile/android/gradle/with_gecko_binaries.gradle.  Instead :app uses
    // :geckoview:release and handles it's own Gecko binary inclusion.
    if (buildType.equals('withGeckoBinaries')) {
        configureVariantWithGeckoBinaries(variant)
    }

    // Javadoc and Sources JAR configuration cribbed from
    // https://github.com/mapbox/mapbox-gl-native/blob/d169ea55c1cfa85cd8bf19f94c5f023569f71810/platform/android/MapboxGLAndroidSDK/build.gradle#L85
    // informed by
    // https://code.tutsplus.com/tutorials/creating-and-publishing-an-android-library--cms-24582,
    // and amended from numerous Stackoverflow posts.
    def name = variant.name
    def javadoc = task "javadoc${name.capitalize()}"(type: Javadoc) {
        description = "Generate Javadoc for build variant $name"
        failOnError = false
        destinationDir = new File(destinationDir, variant.baseName)
        source = files(variant.javaCompile.source)
        classpath = files(variant.javaCompile.classpath.files) + files(android.bootClasspath)
        options.windowTitle("Mozilla GeckoView Android API $VERSION_NAME Reference")
        options.docTitle("Mozilla GeckoView Android API $VERSION_NAME")
        options.header("Mozilla GeckoView Android API $VERSION_NAME Reference")
        options.bottom("© 2016 Mozilla. All rights reserved.")
        options.links("http://docs.oracle.com/javase/7/docs/api/")
        options.linksOffline("http://d.android.com/reference/", "$System.env.ANDROID_HOME/docs/reference")
        // TODO: options.overview("src/main/java/overview.html")
        options.group("Mozilla GeckoView", "org.mozilla.gecko*") // TODO: narrow this down.
        exclude '**/R.java', '**/BuildConfig.java', 'com/googlecode/**'
    }

    task "javadocJar${name.capitalize()}"(type: Jar, dependsOn: javadoc) {
        classifier = 'javadoc'
        from javadoc.destinationDir
    }

    task "sourcesJar${name.capitalize()}"(type: Jar) {
        classifier 'sources'
        description = "Generate Javadoc for build variant $name"
        destinationDir = new File(destinationDir, variant.baseName)
        from files(variant.javaCompile.source)
    }
}

apply plugin: 'maven'
 
uploadArchives {
    repositories.mavenDeployer {
        pom.groupId = 'org.mozilla'
        pom.artifactId = 'geckoview'
        pom.version = VERSION_NAME
        pom.project {
            licenses {
                license {
                    name 'The Mozilla Public License, v. 2.0'
                    url 'http://mozilla.org/MPL/2.0/'
                    distribution 'repo'
                }
            }
        }
        repository(url: "file://${project.buildDir}/maven")
    }
}

// This is all related to the withGeckoBinaries approach; see
// mobile/android/gradle/with_gecko_binaries.gradle.
afterEvaluate {
    // The bundle tasks are only present when the particular configuration is
    // being built, so this task might not exist.  (This is due to the way the
    // Android Gradle plugin defines things during configuration.)
    def bundleWithGeckoBinaries = tasks.findByName('bundleWithGeckoBinaries')
    if (!bundleWithGeckoBinaries) {
        return
    }

    // Remove default configuration, which is the release configuration, when
    // we're actually building withGeckoBinaries.  This makes `gradle install`
    // install the withGeckoBinaries artifacts, not the release artifacts (which
    // are withoutGeckoBinaries and not suitable for distribution.)
    def Configuration archivesConfig = project.getConfigurations().getByName('archives')
    archivesConfig.artifacts.removeAll { it.extension.equals('aar') }

    artifacts {
        // Instead of default (release) configuration, publish one with Gecko binaries.
        archives bundleWithGeckoBinaries
        // Javadoc and sources for developer ergononomics.
        archives javadocJarWithGeckoBinaries
        archives sourcesJarWithGeckoBinaries
    }
}