wangzhibo
4 天以前 ae6f40460dcd56af6c5f60ba52c883854c3bac55
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
import java.nio.file.Files
 
apply plugin: "com.android.application"
apply plugin: 'com.google.protobuf'
 
tasks.withType(Test) {
    systemProperty "MiFirmwareDir", System.getProperty("MiFirmwareDir", null)
    systemProperty "logback.configurationFile", System.getProperty("user.dir", null) + "/app/src/main/assets/logback.xml"
    systemProperty "GB_LOGFILES_DIR", Files.createTempDirectory("gblog").toString()
}
 
def getVersionCode = { ->
    try {
        def commitCount = providers.exec {
            commandLine('git', 'rev-list', 'HEAD', '--count')
        }.standardOutput.asText.get().trim()
        return Integer.valueOf(commitCount)
    } catch (ignored) {
        return null
    }
}
 
def buildGitChangelog = {
    def allCommits = providers.exec {
        commandLine('git', 'log', '--pretty=format:%h %s')
    }.standardOutput.asText.get()
 
    def commitVersionCode = getVersionCode()
    def includedCommits = 0
    def changelogNode = new Node(null, 'changelog')
 
    allCommits.trim().eachLine { line ->
        if (includedCommits > 100) {
            return true;
        }
 
        def (commitHash, commitMessage) = line.split(" ", 2)
        if (commitMessage.contains("Translated using Weblate")) {
            return true;
        }
 
        def releaseNode = new Node(changelogNode, 'release', [version: commitHash, versioncode: commitVersionCode--])
        def _ = new Node(releaseNode, 'change', [:], commitMessage)
        includedCommits++
    }
 
    def changelogFile = new File("${project.rootDir}/app/build/generated/res/changelog/xml/changelog_git.xml")
    changelogFile.getParentFile().mkdirs()
    changelogFile.write(groovy.xml.XmlUtil.serialize(changelogNode))
}
 
def getGitHashShort = { ->
    try {
        return providers.exec {
            commandLine('git', 'rev-parse', '--short', 'HEAD')
        }.standardOutput.asText.get().trim()
    } catch (ignored) {
        return null
    }
}
 
android {
    compileOptions {
        coreLibraryDesugaringEnabled true
 
        // for Android 5+
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
 
    namespace 'nodomain.freeyourgadget.gadgetbridge'
 
    defaultConfig {
        applicationId "com.jsbogang.womp.android"
 
        //noinspection OldTargetApi
        targetSdkVersion 34
        compileSdk 34
        minSdkVersion 21
 
        // Note: always bump BOTH versionCode and versionName!
        versionName "0.83.0"
        versionCode 235
        vectorDrawables.useSupportLibrary = true
        buildConfigField "String", "GIT_HASH_SHORT", "\"${getGitHashShort()}\""
        buildConfigField "boolean", "INTERNET_ACCESS", "true"
    }
 
    signingConfigs {
        nightly {
            if (System.getProperty("nightly_store_file") != null) {
                storeFile file(System.getProperty("nightly_store_file"))
                storePassword System.getProperty("nightly_store_password")
                keyAlias System.getProperty("nightly_key_alias")
                keyPassword System.getProperty("nightly_key_password")
            }
        }
    }
 
    flavorDimensions "device_type"
    productFlavors {
        mainline {
            // Ensure that when starting from scratch, 'mainline' is selected, not 'banglejs'
            getIsDefault().set(true)
            // the default build product flavor
            dimension "device_type"
            //applicationIdSuffix ""
            //versionNameSuffix ""
        }
 
        banglejs {
            dimension "device_type"
            applicationId "com.espruino.gadgetbridge"
            applicationIdSuffix ".banglejs"
            versionNameSuffix "-banglejs"
            buildConfigField "boolean", "INTERNET_ACCESS", "true"
            targetSdkVersion 34
            // Note: app/src/banglejs/AndroidManifest.xml contains some extra permissions
        }
    }
 
    sourceSets {
        main {
            res.srcDirs += "build/generated/res/changelog"
        }
    }
 
    buildTypes {
        release {
            minifyEnabled true
            //proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
        }
 
        nightly {
            applicationIdSuffix ".nightly"
            versionNameSuffix "-${getGitHashShort}"
            //proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
            minifyEnabled true
            debuggable false
 
            if (System.getProperty("nightly_store_file") != null) {
                signingConfig signingConfigs.nightly
            } else {
                signingConfig signingConfigs.debug
            }
        }
 
        nopebble {
            applicationIdSuffix ".nightly_nopebble"
            versionNameSuffix "-${getGitHashShort}"
            //proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
            minifyEnabled true
            debuggable false
 
            if (System.getProperty("nightly_store_file") != null) {
                signingConfig signingConfigs.nightly
            } else {
                signingConfig signingConfigs.debug
            }
        }
 
        applicationVariants.all { variant ->
            variant.resValue "string", "applicationId", variant.applicationId
            buildGitChangelog()
 
            if (variant.buildType.name == 'nightly' || variant.buildType.name == 'nopebble') {
                variant.outputs.all {
                    setVersionCodeOverride(getVersionCode())
                    //setVersionNameOverride(getGitHashShort())
                    setVersionNameOverride(variant.versionName)
                    outputFileName = "${applicationId}_${variant.versionName}.apk"
                }
            }
        }
    }
 
    lint {
        abortOnError true
        lintConfig file("$rootDir/app/src/main/lint.xml")
        // If true, generate an HTML report (with issue explanations, sourcecode, etc)
        htmlReport true
        // Optional path to report (default will be lint-results.html in the builddir)
        htmlOutput file("$project.buildDir/reports/lint/lint.html")
        // Ignore checks present in the snapshot
        baseline file("lint-baseline.xml")
    }
 
    testOptions {
        unitTests {
            returnDefaultValues = true
            includeAndroidResources = true
        }
    }
    buildFeatures {
        aidl true
        buildConfig true
    }
}
 
dependencies {
    coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.1.3'
 
    implementation 'androidx.constraintlayout:constraintlayout:2.2.0'
    implementation "androidx.camera:camera-core:1.4.1"
    implementation "androidx.camera:camera-camera2:1.4.1"
    implementation 'androidx.camera:camera-view:1.4.1'
    implementation 'androidx.camera:camera-lifecycle:1.4.1'
 
    testImplementation "junit:junit:4.13.2"
    testImplementation "org.mockito:mockito-core:5.14.2"
    testImplementation "org.robolectric:robolectric:4.14.1"
    testImplementation "org.hamcrest:hamcrest-library:3.0"
 
    implementation "androidx.appcompat:appcompat:1.7.0"
    implementation "androidx.preference:preference:1.2.1"
    implementation "androidx.cardview:cardview:1.0.0"
    implementation "androidx.recyclerview:recyclerview:1.3.2"
    implementation "androidx.legacy:legacy-support-v4:1.0.0"
    implementation "androidx.gridlayout:gridlayout:1.0.0"
    implementation "androidx.palette:palette:1.0.0"
    implementation "androidx.activity:activity:1.9.3"
    implementation "androidx.fragment:fragment:1.8.5"
    implementation "androidx.viewpager2:viewpager2:1.1.0"
 
    // Not latest version because of https://github.com/material-components/material-components-android/issues/3924
    implementation "com.google.android.material:material:1.10.0"
    implementation 'com.google.android.flexbox:flexbox:3.0.0'
    implementation "com.google.code.gson:gson:2.11.0"
 
    implementation "no.nordicsemi.android:dfu:2.5.0"
    implementation "com.github.tony19:logback-android:3.0.0"
    implementation "org.slf4j:slf4j-api:2.0.16"
    implementation "com.github.PhilJay:MPAndroidChart:3.1.0"
    implementation "com.github.pfichtner:durationformatter:0.1.1"
    implementation "de.cketti.library.changelog:ckchangelog:1.2.2"
    implementation "net.e175.klaus:solarpositioning:0.1.10"
    implementation "co.nstant.in:cbor:0.9"
    // use pristine greendao instead of our custom version, since our custom jitpack-packaged
    // version contains way too much and our custom patches are in the generator only.
    implementation "org.greenrobot:greendao:2.2.1"
    implementation "org.apache.commons:commons-lang3:3.17.0"
    implementation "org.cyanogenmod:platform.sdk:6.0"
    implementation 'com.jaredrummler:colorpicker:1.1.0'
    implementation 'com.github.wax911.android-emojify:contract:1.9.5'
    implementation 'com.github.wax911.android-emojify:emojify:1.9.5'
    implementation 'com.github.wax911.android-emojify:gson:1.9.5'
    implementation 'com.google.protobuf:protobuf-javalite:4.29.1'
    implementation 'com.android.volley:volley:1.2.1'
    implementation 'com.google.zxing:core:3.5.3'
    implementation 'org.msgpack:msgpack-core:0.9.8'
 
    // Bouncy Castle is included directly in GB, to avoid pulling the entire dependency
    // It's included in the org.bouncycastle.shaded package, to fix conflicts with roboelectric
    //implementation 'org.bouncycastle:bcpkix-jdk18on:1.76'
    //implementation 'org.bouncycastle:bcprov-jdk18on:1.76'
 
    // Android SDK bundles org.json, but we need an actual implementation to replace the stubs in tests
    testImplementation 'org.json:json:20240303'
 
    // Fix Duplicate class build error for conflicting kotlin-stdlib versions
    // does not seem to be currently needed, as it uses the latest across all transitive
    //implementation(platform("org.jetbrains.kotlin:kotlin-bom:1.8.0"))
 
    // Needed for Armenian transliteration
    implementation 'org.ahocorasick:ahocorasick:0.6.3'
}
 
preBuild.dependsOn(":GBDaoGenerator:genSources")
 
//gradle.beforeProject {
//    preBuild.dependsOn(":GBDaoGenerator:genSources")
//}
 
sourceSets {
    main {
        java.srcDirs += "${protobuf.generatedFilesBaseDir}"
        java.srcDirs += "build/generated/source/buildConfig"
    }
}
 
tasks.register('cleanGenerated', Delete) {
    delete fileTree('src/main/java/nodomain/freeyourgadget/gadgetbridge/entities') {
        include '**/*.java'
        exclude '**/Abstract*.java'
    }
}
 
tasks.clean.dependsOn(tasks.cleanGenerated)
 
protobuf {
    protoc {
        artifact = 'com.google.protobuf:protoc:4.29.1'
    }
    generateProtoTasks {
        all().each { task ->
            task.builtins {
                java {
                    option 'lite'
                }
            }
        }
    }
}