Skip to content

A cross platform Audiobookshelf client for Android and iOS

Dart

Add a dev flavor that installs beside the stable app as Absorb Dev

Barnabas238f9369c87c
diff --git a/android/app/build.gradle.kts b/android/app/build.gradle.kts
index 90112c3c..f3804d10 100644
--- a/android/app/build.gradle.kts
+++ b/android/app/build.gradle.kts
@@ -47,6 +47,7 @@ android {
targetSdk = flutter.targetSdkVersion
versionCode = flutter.versionCode
versionName = flutter.versionName
+ resValue("string", "app_name", "Absorb")
buildConfigField(
"int",
"ABSORB_BASE_VERSION_CODE",
@@ -68,6 +69,14 @@ android {
dimension = "distribution"
proguardFiles("proguard-flutter-keep.pro")
}
+ // Local testing build that installs beside the stable app: its own
+ // application id, name and icon tint, otherwise the github build.
+ create("dev") {
+ dimension = "distribution"
+ applicationIdSuffix = ".dev"
+ resValue("string", "app_name", "Absorb Dev")
+ proguardFiles("proguard-flutter-keep.pro")
+ }
// GMS-free build for F-Droid: no Chromecast, Wear bridge, or in-app updater.
create("fdroid") {
dimension = "distribution"
@@ -81,6 +90,7 @@ android {
sourceSets {
getByName("github").java.srcDir("src/gms/kotlin")
getByName("playstore").java.srcDir("src/gms/kotlin")
+ getByName("dev").java.srcDir("src/gms/kotlin")
}
buildTypes {
@@ -130,8 +140,9 @@ android {
// word "universal" stays in the name because newer updaters match it
// as a token when no per-ABI build fits.
val packageKind = abi ?: "all-universal"
+ val flavorTag = if (variant.flavorName == "dev") "-dev" else ""
output.outputFileName =
- "absorb-${variant.versionName}-${variant.versionCode}-$packageKind.apk"
+ "absorb-${variant.versionName}-${variant.versionCode}$flavorTag-$packageKind.apk"
}
}
}
@@ -159,6 +170,7 @@ dependencies {
gmsImpl.forEach {
add("githubImplementation", it)
add("playstoreImplementation", it)
+ add("devImplementation", it)
}
}
diff --git a/android/app/src/dev/res/values/colors.xml b/android/app/src/dev/res/values/colors.xml
new file mode 100644
index 00000000..ac846293
--- /dev/null
+++ b/android/app/src/dev/res/values/colors.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+ <!-- Dev flavor: same launcher icon on a red ground, so the testing install is
+ told apart from the stable one at a glance. -->
+ <color name="ic_launcher_background">#B3261E</color>
+</resources>
diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml
index da791b69..f39b58d1 100644
--- a/android/app/src/main/AndroidManifest.xml
+++ b/android/app/src/main/AndroidManifest.xml
@@ -27,7 +27,7 @@
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" tools:node="remove"/>
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO" tools:node="remove"/>
- <application android:label="Absorb" android:name="${applicationName}" android:icon="@mipmap/ic_launcher" android:networkSecurityConfig="@xml/network_security_config" android:largeHeap="true">
+ <application android:label="@string/app_name" android:name="${applicationName}" android:icon="@mipmap/ic_launcher" android:networkSecurityConfig="@xml/network_security_config" android:largeHeap="true">
<activity android:name=".MainActivity" android:exported="true" android:launchMode="singleTask" android:theme="@style/LaunchTheme" android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode" android:hardwareAccelerated="true" android:windowSoftInputMode="adjustResize">
<meta-data android:name="io.flutter.embedding.android.NormalTheme" android:resource="@style/NormalTheme"/>
@@ -96,7 +96,7 @@
<!-- Send covers to AA while offline -->
<provider
android:name=".CoverContentProvider"
- android:authorities="com.barnabas.absorb.covers"
+ android:authorities="${applicationId}.covers"
android:exported="true"
android:grantUriPermissions="true" />
diff --git a/android/app/src/main/kotlin/com/barnabas/absorb/CoverContentProvider.kt b/android/app/src/main/kotlin/com/barnabas/absorb/CoverContentProvider.kt
index bc7e0287..2557f048 100644
--- a/android/app/src/main/kotlin/com/barnabas/absorb/CoverContentProvider.kt
+++ b/android/app/src/main/kotlin/com/barnabas/absorb/CoverContentProvider.kt
@@ -18,7 +18,7 @@ import org.json.JSONObject
*
* Android Auto cannot load HTTP or file:// URIs directly — it requires
* content:// URIs. This provider maps:
- * content://com.barnabas.absorb.covers/cover/<itemId>
+ * content://<applicationId>.covers/cover/<itemId>
*
* Lookup order:
* 1. Locally downloaded cover (item's download directory)
@@ -28,12 +28,16 @@ import org.json.JSONObject
class CoverContentProvider : ContentProvider() {
companion object {
- const val AUTHORITY = "com.barnabas.absorb.covers"
private const val TAG = "CoverProvider"
private val refreshLock = Any()
- fun buildCoverUri(itemId: String): Uri {
- return Uri.parse("content://$AUTHORITY/cover/$itemId")
+ // Per install: the dev flavor sits beside the stable app under its own
+ // application id, and two apps can't share a provider authority.
+ fun authority(context: android.content.Context): String =
+ "${context.packageName}.covers"
+
+ fun buildCoverUri(context: android.content.Context, itemId: String): Uri {
+ return Uri.parse("content://${authority(context)}/cover/$itemId")
}
}
diff --git a/lib/screens/settings_screen.dart b/lib/screens/settings_screen.dart
index 2bbc0df1..54a9c224 100644
--- a/lib/screens/settings_screen.dart
+++ b/lib/screens/settings_screen.dart
@@ -62,10 +62,12 @@ class SettingsScreen extends StatefulWidget {
class _SettingsScreenState extends State<SettingsScreen> {
static const _isPlayStoreBuild = bool.fromEnvironment('PLAYSTORE_BUILD');
static const _isGithubBuild = bool.fromEnvironment('GITHUB_BUILD');
+ static const _isDevBuild = bool.fromEnvironment('DEV_BUILD');
// Distribution label shown next to the version. The F-Droid build passes
- // neither define, so it falls through here.
- static String get _flavorLabel =>
- _isGithubBuild ? 'GitHub' : _isPlayStoreBuild ? 'Play Store' : 'F-Droid';
+ // no define, so it falls through here.
+ static String get _flavorLabel => _isDevBuild
+ ? 'Dev'
+ : _isGithubBuild ? 'GitHub' : _isPlayStoreBuild ? 'Play Store' : 'F-Droid';
String _versionLine(AppLocalizations l) {
final base = Platform.isIOS
diff --git a/lib/services/android_auto_service.dart b/lib/services/android_auto_service.dart
index 262cd608..4a195d4c 100644
--- a/lib/services/android_auto_service.dart
+++ b/lib/services/android_auto_service.dart
@@ -437,8 +437,9 @@ class AndroidAutoService {
}
/// Content provider authority for serving local cover images to Android Auto.
- /// Must match the authority registered in AndroidManifest.xml.
- static const _coverAuthority = 'com.barnabas.absorb.covers';
+ /// Follows the installed package, as the manifest's `${applicationId}.covers`
+ /// does, so the dev flavor reaches its own provider.
+ static String get _coverAuthority => '${ApiService.packageName}.covers';
// Per-item updatedAt for cover ?ts= cache busting on AA/CarPlay.
static final Map<String, int> _itemUpdatedAt = {};
diff --git a/lib/services/api_service.dart b/lib/services/api_service.dart
index 56f212b6..5a228a07 100644
--- a/lib/services/api_service.dart
+++ b/lib/services/api_service.dart
@@ -202,6 +202,10 @@ class ApiService {
static String appVersion = '1.3.0'; // fallback; overwritten by initVersion()
static String appBuild = ''; // build number; set by initVersion()
+ // The installed application id. The dev flavor installs beside the stable
+ // app under its own id, so anything that names the package at runtime (the
+ // cover content provider's authority) reads this rather than assuming.
+ static String packageName = 'com.barnabas.absorb'; // set by initVersion()
/// Version plus build (e.g. "1.9.1+198") for logs. `appVersion` stays clean
/// because it's also sent to the server as clientVersion.
@@ -225,6 +229,7 @@ class ApiService {
final info = await PackageInfo.fromPlatform();
appVersion = info.version;
appBuild = info.buildNumber;
+ if (info.packageName.isNotEmpty) packageName = info.packageName;
} catch (_) {}
}
diff --git a/lib/services/audio_player_service.dart b/lib/services/audio_player_service.dart
index e2dc97dd..454b1899 100644
--- a/lib/services/audio_player_service.dart
+++ b/lib/services/audio_player_service.dart
@@ -4986,8 +4986,10 @@ class AudioPlayerService extends ChangeNotifier {
return null;
}
- /// Content provider authority — must match CoverContentProvider and AndroidManifest.
- static const _coverAuthority = 'com.barnabas.absorb.covers';
+ /// Content provider authority. Follows the installed package, as the
+ /// manifest's `${applicationId}.covers` does, so the dev flavor reaches its
+ /// own provider.
+ static String get _coverAuthority => '${ApiService.packageName}.covers';
void _pushMediaItem(
String itemId,
diff --git a/lib/services/home_widget_service.dart b/lib/services/home_widget_service.dart
index 3ade5955..6f9c3420 100644
--- a/lib/services/home_widget_service.dart
+++ b/lib/services/home_widget_service.dart
@@ -20,6 +20,10 @@ const String _androidWidgetName = 'NowPlayingWidget';
const String _androidWidgetCompactName = 'NowPlayingWidgetCompact';
const String _androidWidgetTinyName = 'NowPlayingWidgetTiny';
const String _androidWidgetStatsName = 'StatsWidget';
+// The widgets' Kotlin package. It stays put when the dev flavor changes the
+// application id, and home_widget would otherwise look the classes up under
+// the new id and find nothing.
+const String _androidWidgetPackage = 'com.barnabas.absorb';
const String _iOSWidgetName = 'NowPlayingWidget';
const String _iOSArtWidgetName = 'NowPlayingArtWidget';
const String _iOSStatsWidgetName = 'StatsWidget';
@@ -878,10 +882,17 @@ class HomeWidgetService {
Future<void> _updateAllWidgets() async {
if (Platform.isAndroid) {
- await HomeWidget.updateWidget(name: _androidWidgetName);
- await HomeWidget.updateWidget(name: _androidWidgetCompactName);
- await HomeWidget.updateWidget(name: _androidWidgetTinyName);
- await HomeWidget.updateWidget(name: _androidWidgetStatsName);
+ for (final name in [
+ _androidWidgetName,
+ _androidWidgetCompactName,
+ _androidWidgetTinyName,
+ _androidWidgetStatsName,
+ ]) {
+ await HomeWidget.updateWidget(
+ name: name,
+ qualifiedAndroidName: '$_androidWidgetPackage.$name',
+ );
+ }
} else if (Platform.isIOS) {
await HomeWidget.updateWidget(iOSName: _iOSWidgetName);
await HomeWidget.updateWidget(iOSName: _iOSArtWidgetName);
@@ -891,7 +902,10 @@ class HomeWidgetService {
Future<void> _updateStatsWidget() async {
if (Platform.isAndroid) {
- await HomeWidget.updateWidget(name: _androidWidgetStatsName);
+ await HomeWidget.updateWidget(
+ name: _androidWidgetStatsName,
+ qualifiedAndroidName: '$_androidWidgetPackage.$_androidWidgetStatsName',
+ );
} else if (Platform.isIOS) {
await HomeWidget.updateWidget(iOSName: _iOSStatsWidgetName);
}