Skip to content
This repository has been archived by the owner on Feb 14, 2025. It is now read-only.

Commit

Permalink
feat: add versionCode to ConfigureShorebird (#15)
Browse files Browse the repository at this point in the history
* feat: add versionCode to ConfigureShorebird

* Include the version_code in the release_version

---------

Co-authored-by: Felix Angelov <felix@shorebird.dev>
  • Loading branch information
eseidel and felangel committed Sep 21, 2023
1 parent 19aadc1 commit 4799fd9
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
14 changes: 10 additions & 4 deletions shell/platform/android/flutter_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ extern "C" __attribute__((weak)) unsigned long getauxval(unsigned long type) {
void ConfigureShorebird(std::string android_cache_path,
flutter::Settings& settings,
std::string shorebirdYaml,
std::string version) {
std::string version,
long version_code) {
auto cache_dir =
fml::paths::JoinPaths({android_cache_path, "shorebird_updater"});

Expand All @@ -107,7 +108,10 @@ void ConfigureShorebird(std::string android_cache_path,
// Using a block to make AppParameters lifetime explicit.
{
AppParameters app_parameters;
app_parameters.release_version = version.c_str();
// Combine version and version_code into a single string.
// We could also pass these separately through to the updater if needed.
auto release_version = version + "+" + std::to_string(version_code);
app_parameters.release_version = release_version.c_str();
app_parameters.cache_dir = cache_dir.c_str();

// https://stackoverflow.com/questions/26032039/convert-vectorstring-into-char-c
Expand Down Expand Up @@ -160,6 +164,7 @@ void FlutterMain::Init(JNIEnv* env,
jstring engineCachesPath,
jstring shorebirdYaml,
jstring version,
jlong versionCode,
jlong initTimeMillis) {
std::vector<std::string> args;
args.push_back("flutter");
Expand Down Expand Up @@ -201,8 +206,9 @@ void FlutterMain::Init(JNIEnv* env,
#if FLUTTER_RELEASE
std::string shorebird_yaml = fml::jni::JavaStringToString(env, shorebirdYaml);
std::string version_string = fml::jni::JavaStringToString(env, version);
long version_code = versionCode;
ConfigureShorebird(android_cache_path, settings, shorebird_yaml,
version_string);
version_string, version_code);
#endif

flutter::DartCallbackCache::LoadCacheFromDisk();
Expand Down Expand Up @@ -292,7 +298,7 @@ bool FlutterMain::Register(JNIEnv* env) {
.name = "nativeInit",
.signature = "(Landroid/content/Context;[Ljava/lang/String;Ljava/"
"lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/"
"lang/String;Ljava/lang/String;J)V",
"lang/String;Ljava/lang/String;JJ)V",
.fnPtr = reinterpret_cast<void*>(&Init),
},
{
Expand Down
1 change: 1 addition & 0 deletions shell/platform/android/flutter_main.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class FlutterMain {
jstring engineCachesPath,
jstring shorebirdYaml,
jstring version,
jlong versionCode,
jlong initTimeMillis);

void SetupDartVMServiceUriCallback(JNIEnv* env);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import android.content.Context;
import android.content.pm.PackageManager;
import android.content.pm.PackageInfo;
import android.content.res.AssetManager;
import android.graphics.Bitmap;
import android.graphics.ColorSpace;
Expand Down Expand Up @@ -176,6 +177,7 @@ private static native void nativeInit(
@NonNull String engineCachesPath,
@Nullable String shorebirdYaml,
@Nullable String version,
long versionCode,
long initTimeMillis);

/**
Expand All @@ -202,11 +204,11 @@ public void init(
}

String version = null;
long versionCode = 0;
try {
// Should this be versionName or getLongVersionCode()?
// versionName is human readable, but getLongVersionCode() is a
// monotonically increasing number.
version = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName;
PackageInfo packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
version = packageInfo.versionName;
versionCode = packageInfo.getLongVersionCode();
} catch (PackageManager.NameNotFoundException e) {
Log.e(TAG, "Failed to read app version. Shorebird updater can't run.", e);
}
Expand All @@ -233,6 +235,7 @@ public void init(
engineCachesPath,
shorebirdYaml,
version,
versionCode,
initTimeMillis);
FlutterJNI.initCalled = true;
}
Expand Down

0 comments on commit 4799fd9

Please sign in to comment.