Skip to content

Commit

Permalink
build: 一些基础更新 | Some basic updates (#14)
Browse files Browse the repository at this point in the history
* build: Update the implementation component version

* build: Modify APK naming

* build: Add debug package build

* style: Naming convention lowercase.
  • Loading branch information
wwxiaoqi authored Apr 13, 2024
1 parent 123f461 commit d92c80e
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 12 deletions.
31 changes: 27 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,20 @@ plugins {
id 'com.android.application'
}

// By appending the version name, build type, and a timestamp to the APK filename,
// it becomes very easy for testers and developers to identify exactly which version of the application they are testing.
// This is particularly useful when multiple versions or builds are being tested simultaneously.
// Testers don’t need to manually rename APKs to keep track of different builds or worry about which version is the latest.
android.applicationVariants.configureEach { variant ->
variant.outputs.configureEach { output ->
def formattedDate = new Date().format('yyyyMMddHHmmss')
def versionName = variant.versionName
def buildType = variant.buildType.name
def newApkName = "siyuan-${versionName}-${buildType}-${formattedDate}.apk"
output.outputFileName = newApkName
}
}

android {
compileSdkVersion 34
buildToolsVersion "34"
Expand All @@ -18,6 +32,15 @@ android {
release {
minifyEnabled true
shrinkResources true
resValue "string", "app_name", "SiYuan"
resValue "string", "app_package_name", "org.b3log.siyuan"
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
debug {
applicationIdSuffix ".debug"
minifyEnabled false
resValue "string", "app_name", "SiYuan-Debug"
resValue "string", "app_package_name", "org.b3log.siyuan.debug"
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
Expand Down Expand Up @@ -56,10 +79,10 @@ android {
}

dependencies {
implementation 'androidx.appcompat:appcompat:1.6.0'
implementation 'com.google.android.material:material:1.8.0'
implementation 'androidx.lifecycle:lifecycle-process:2.5.1'
implementation 'androidx.work:work-runtime:2.7.1'
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.10.0'
implementation 'androidx.lifecycle:lifecycle-process:2.6.1'
implementation 'androidx.work:work-runtime:2.8.1'

implementation(name: 'kernel', ext: 'aar')
implementation("commons-io:commons-io:2.5") // 不要升级,否则无法兼容 Android 7
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
<!-- Support opening assets through other apps on the Android /~https://github.com/siyuan-note/siyuan/issues/10657 -->
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="org.b3log.siyuan"
android:authorities="@string/app_package_name"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
Expand Down
30 changes: 30 additions & 0 deletions app/src/main/java/org/b3log/siyuan/DebugModeChecker.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package org.b3log.siyuan;

import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;

public class DebugModeChecker {

/**
* Checks if the current package name contains ".debug" and if debug mode is enabled.
*
* @param context The Android context used to retrieve the package information.
* @return true if the package name contains ".debug" and debug mode is enabled, false otherwise.
*/
public static boolean isDebugPackageAndMode(Context context) {
PackageManager packageManager = context.getPackageManager();
ApplicationInfo appInfo = null;
try {
appInfo = packageManager.getApplicationInfo(context.getPackageName(), 0);
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}

// Check if the package name contains ".debug"
boolean isDebugPackage = context.getPackageName() != null && context.getPackageName().contains(".debug");
boolean isDebugMode = appInfo != null && (appInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0;
return isDebugPackage && isDebugMode;
}

}
2 changes: 1 addition & 1 deletion app/src/main/java/org/b3log/siyuan/JSAndroid.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public void openExternal(String url) {
} else {
asset = new File(workspacePath, "data/" + url);
}
final Uri uri = FileProvider.getUriForFile(activity.getApplicationContext(), "org.b3log.siyuan", asset);
final Uri uri = FileProvider.getUriForFile(activity.getApplicationContext(), BuildConfig.APPLICATION_ID, asset);
final String type = Mobile.getMimeTypeByExt(asset.getAbsolutePath());
Intent intent = new ShareCompat.IntentBuilder(activity.getApplicationContext())
.setStream(uri)
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/org/b3log/siyuan/KeepLiveService.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ private void startMyOwnForeground() {
resultPendingIntent = PendingIntent.getActivity(this, 0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT);
}

final String NOTIFICATION_CHANNEL_ID = "org.b3log.siyuan";
final String NOTIFICATION_CHANNEL_ID = BuildConfig.APPLICATION_ID;
final String channelName = "SiYuan Kernel Service";
final NotificationChannel chan = new NotificationChannel(NOTIFICATION_CHANNEL_ID, channelName, NotificationManager.IMPORTANCE_NONE);
chan.setLightColor(Color.BLUE);
Expand Down
8 changes: 6 additions & 2 deletions app/src/main/java/org/b3log/siyuan/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,9 @@ protected void onCreate(final Bundle savedInstanceState) {
AppUtils.registerAppStatusChangedListener(this);

// 使用 Chromium 调试 WebView
// WebView.setWebContentsDebuggingEnabled(true);
if (DebugModeChecker.isDebugPackageAndMode(this)) {
WebView.setWebContentsDebuggingEnabled(true);
}

// 注册工具栏显示/隐藏跟随软键盘状态
// Fix /~https://github.com/siyuan-note/siyuan/issues/9765
Expand Down Expand Up @@ -340,7 +342,9 @@ private void startHttpServer() {
// 生产环境绑定 ipv6 回环地址 [::1] 以防止被远程访问
s.listen(InetAddress.getLoopbackAddress(), serverPort, server.getListenCallback());
// 开发环境绑定所有网卡以便调试
//s.listen(null, serverPort, server.getListenCallback());
if (DebugModeChecker.isDebugPackageAndMode(this)) {
s.listen(null, serverPort, server.getListenCallback());
}
Utils.LogInfo("http", "HTTP server is listening on port [" + serverPort + "]");
}

Expand Down
3 changes: 0 additions & 3 deletions app/src/main/res/values/strings.xml

This file was deleted.

0 comments on commit d92c80e

Please sign in to comment.