Skip to content

Commit

Permalink
feat(android): foss compliant build for F-Droid
Browse files Browse the repository at this point in the history
  • Loading branch information
azarz committed Jun 28, 2024
1 parent 9e8bb84 commit 5a3ebbf
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 7 deletions.
21 changes: 21 additions & 0 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,18 @@ android {
ignoreAssetsPattern '!.svn:!.git:!.ds_store:!*.scc:.*:!CVS:!thumbs.db:!picasa.ini:!*~'
}
}

flavorDimensions "default"
productFlavors {
google {
dimension "default"
}
fdroid {
dimension "default"
versionNameSuffix "+foss"
}
}

buildTypes {
release {
minifyEnabled false
Expand Down Expand Up @@ -44,6 +56,15 @@ dependencies {

apply from: 'capacitor.build.gradle'

project.afterEvaluate {
if (project.hasProperty("buildFlavor")) {
def buildFlavor = project.property("buildFlavor")
if (buildFlavor == "google") {
apply from: 'build_google.gradle'
}
}
}

try {
def servicesJSON = file('google-services.json')
if (servicesJSON.text) {
Expand Down
11 changes: 11 additions & 0 deletions android/app/build_google.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
buildscript {
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.google.gms:google-services:4.4.0'
}
}

apply plugin: 'com.google.gms.google-services'
4 changes: 2 additions & 2 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {

repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:8.2.1'
classpath 'com.google.gms:google-services:4.4.0'
// classpath 'com.google.gms:google-services:4.4.0'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
"build:dev": "webpack --config webpack.dev.js",
"serve:dev": "webpack-dev-server --config webpack.dev.js --hot",
"run:android": "npm run build:dev && npx cap sync && npx cap run android",
"build:android": "npm run build && npx cap sync && cd android && ./gradlew assembleRelease",
"build:android": "npm run build && npx cap sync && cd android && ./gradlew assembleRelease -PbuildFlavor=google",
"build:android:foss": "npm run build && npx cap sync && cd android && ./gradlew assembleRelease -PbuildFlavor=fdroid",
"build:android:dev": "npm run build:dev && npx cap sync && cd android && ./gradlew",
"build:android:foss:dev": "npm run build:dev && npx cap sync && cd android && ./gradlew -PbuildFlavor=fdroid",
"bump:version": "echo 'npm run bump:app:versions -- $1' > temp.sh && echo 'npm version $1 --git-tag-version false' >> temp.sh && echo 'git add -u && git commit -m \"$1\" && git tag v$1' >> temp.sh && sh temp.sh",
"postbump:version": "rm temp.sh",
"bump:app:versions": "python bump_version.py"
Expand Down
17 changes: 13 additions & 4 deletions src/js/services/location.js
Original file line number Diff line number Diff line change
Expand Up @@ -401,10 +401,19 @@ const getLocation = async () => {
if (currentPosition === null) {
await enablePosition();
// Récupération rapide de la position si elle n'est pas connue
position = await Geolocation.getCurrentPosition({
maximumAge: 0,
timeout: 3000,
});
if (Capacitor.getPlatform() === "android") {
position = await new Promise( (resolve, reject) => {
navigator.geolocation.getCurrentPosition(resolve, reject, {
maximumAge: 0,
timeout: 3000,
});
});
} else {
position = await Geolocation.getCurrentPosition({
maximumAge: 0,
timeout: 3000,
});
}
}

results = {
Expand Down

0 comments on commit 5a3ebbf

Please sign in to comment.