Skip to content

Commit 2794d2f

Browse files
authored
refine API and fix Android connect check (#5)
* refine API and fix Android connect check * fix ci * use API 29 for Android connected check * fix macApp compile
1 parent e7dac38 commit 2794d2f

File tree

16 files changed

+59
-29
lines changed

16 files changed

+59
-29
lines changed

.github/workflows/ci.yaml

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ jobs:
2121
include:
2222
- os: macos-latest
2323
cmd: "./gradlew :kmp-xlog:testDebugUnitTest"
24-
- os: macos-latest
25-
cmd: "./gradlew :example:androidApp:assembleDebug"
24+
- os: ubuntu-latest
25+
androidEmulator: true
26+
cmd: "./gradlew :example:androidApp:connectedCheck"
2627
- os: macos-latest
2728
dep: "brew update && brew install xcodegen"
2829
cmd: "./scripts/build_apple.sh && ./gradlew runKmp_xlogDebugExecutableMacosX64 && ./scripts/build_mac_demo.sh && ./scripts/build_ios_demo.sh"
@@ -55,5 +56,20 @@ jobs:
5556
- name: Install deps
5657
if: ${{ matrix.dep }}
5758
run: ${{ matrix.dep }}
58-
- name: Run it
59+
- name: Enable KVM for Android Emulator
60+
if: ${{ matrix.androidEmulator }}
61+
run: |
62+
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
63+
sudo udevadm control --reload-rules
64+
sudo udevadm trigger --name-match=kvm
65+
- name: Run normal
66+
if: ${{ !matrix.androidEmulator }}
5967
run: ${{ matrix.cmd }}
68+
- name: Run Android connected check
69+
if: ${{ matrix.androidEmulator }}
70+
uses: reactivecircus/android-emulator-runner@v2
71+
with:
72+
api-level: 29
73+
ndk: 21.3.6528147
74+
cmake: 3.18.1
75+
script: ${{ matrix.cmd }}

README.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,21 +51,25 @@ fun initializeMarsXLog(
5151
logDir: String,
5252
level: Int,
5353
namePrefix: String,
54-
debugLog: Boolean
5554
)
5655

5756
// iOS/macOS/Linux/Windows initialize
5857
fun initializeMarsXLog(
5958
level: Int,
6059
namePrefix: String,
61-
debugLog: Boolean
6260
)
6361

6462
// JS initialize
6563
fun initializeConsoleLog(debugLog: Boolean)
6664

6765
// logging
6866
object Logging {
67+
// if debug log is enabled (level is LEVEL_DEBUG)
68+
fun debug(): Boolean
69+
70+
// compute log content lazily, only when debug log is enabled
71+
fun debug(tag: String, block: () -> String)
72+
6973
fun debug(tag: String, content: String)
7074

7175
fun info(tag: String, content: String)
@@ -76,12 +80,14 @@ object Logging {
7680

7781
## Env Setup
7882

79-
You need to install [RVM](https://rvm.io/) to manage your ruby version, and install gems. You need to use homebrew to install the following tools:
83+
You will need cocoapods. You can use [RVM](https://rvm.io/) to manage your ruby version, and install gems.
84+
85+
You need to use homebrew to install the following tools:
8086

8187
```bash
82-
brew install cocoapods xcodegen
88+
brew install xcodegen
8389
# if you have installed them earlier, you need to remove them at first,
84-
# or run brew link --overwrite xcodegen cocoapods
90+
# or run brew link --overwrite xcodegen
8591
```
8692

8793
You may need to restart your system so that Android Studio could use the correct ruby.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
object Consts {
22
const val releaseGroup = "com.piasy"
33
const val releaseName = "kmp-xlog"
4-
const val releaseVersion = "1.4.1"
4+
const val releaseVersion = "1.4.2"
55

66
val androidNS = "$releaseGroup.${releaseName.replace('-', '.')}"
77
}

example/androidApp/build.gradle.kts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ android {
1313
targetSdk = libs.versions.targetSdk.get().toInt()
1414
versionCode = 1
1515
versionName = Consts.releaseVersion
16+
17+
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
1618
}
1719
buildFeatures {
1820
compose = true
@@ -46,4 +48,6 @@ dependencies {
4648
implementation(libs.androidx.compose.foundation)
4749
implementation(libs.androidx.compose.material)
4850
implementation(libs.androidx.activity.compose)
51+
androidTestImplementation(libs.androidx.junit)
52+
androidTestImplementation(libs.androidx.runner)
4953
}

example/androidApp/src/androidTest/java/com/piasy/kmp/xlog/android/LoggingTest.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import androidx.test.ext.junit.runners.AndroidJUnit4
44
import androidx.test.platform.app.InstrumentationRegistry
55
import com.piasy.kmp.xlog.Logging
66
import com.piasy.kmp.xlog.initializeMarsXLog
7-
import org.junit.Assert.*
87
import org.junit.Test
98
import org.junit.runner.RunWith
109

@@ -25,7 +24,6 @@ class LoggingTest {
2524
"${appContext.getExternalFilesDir(null)?.absolutePath}/log",
2625
Logging.LEVEL_DEBUG,
2726
"test",
28-
true
2927
)
3028

3129
Logging.debug("xxx", "test debug log")

example/macApp/macApp/ViewController.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ - (void)viewDidLoad {
3030

3131
[self.view addSubview:self.label];
3232

33-
[Kmp_xlogLoggingKt initializeMarsXLogLevel:1 namePrefix:@"test" debugLog:YES];
33+
[Kmp_xlogLoggingKt initializeMarsXLogLevel:1 namePrefix:@"test"];
3434
[[Kmp_xlogLogging logging] infoTag:@"XXPXX" content:[NSString stringWithFormat:@"greeting from %@", [self getSystemVersion]]];
3535
[[Kmp_xlogLogging logging] errorTag:@"XXPXX" content:@"flush"];
3636
}

example/shared/build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ kotlin {
5454
sourceSets {
5555
commonMain {
5656
dependencies {
57-
//implementation("${Consts.releaseGroup}:${Consts.releaseName}:${Consts.releaseVersion}")
58-
implementation(project(":kmp-xlog"))
57+
//api("${Consts.releaseGroup}:${Consts.releaseName}:${Consts.releaseVersion}")
58+
api(project(":kmp-xlog"))
5959
}
6060
}
6161

example/shared/src/androidMain/kotlin/com/piasy/kmp/xlog/example/Platform.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ class AndroidPlatform : Platform {
1111
actual fun getPlatform(): Platform = AndroidPlatform()
1212

1313
fun initialize(context: Context) {
14-
initializeMarsXLog(context, "logs", Logging.LEVEL_DEBUG, "test", true)
14+
initializeMarsXLog(context, "logs", Logging.LEVEL_DEBUG, "test")
1515
}

example/shared/src/cppCommon/kotlin/com/piasy/kmp/xlog/example/Platform.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ class CppPlatform : Platform {
1010
actual fun getPlatform(): Platform = CppPlatform()
1111

1212
fun main() {
13-
initializeMarsXLog(Logging.LEVEL_DEBUG, "test", true)
13+
initializeMarsXLog(Logging.LEVEL_DEBUG, "test")
1414
println(Greeting().greeting())
1515
}

example/shared/src/iosMain/kotlin/com/piasy/kmp/xlog/example/Platform.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ class IOSPlatform : Platform {
1212
actual fun getPlatform(): Platform = IOSPlatform()
1313

1414
fun initialize() {
15-
initializeMarsXLog(Logging.LEVEL_DEBUG, "test", true)
15+
initializeMarsXLog(Logging.LEVEL_DEBUG, "test")
1616
}

0 commit comments

Comments
 (0)