chore: establish M0 baseline
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
plugins {
|
||||
alias(libs.plugins.android.application)
|
||||
alias(libs.plugins.kotlin.android)
|
||||
}
|
||||
|
||||
android {
|
||||
namespace = "org.neslite.app"
|
||||
compileSdk = 36
|
||||
ndkVersion = "28.2.13676358"
|
||||
|
||||
buildFeatures {
|
||||
buildConfig = true
|
||||
}
|
||||
|
||||
compileOptions {
|
||||
sourceCompatibility = JavaVersion.VERSION_17
|
||||
targetCompatibility = JavaVersion.VERSION_17
|
||||
}
|
||||
|
||||
defaultConfig {
|
||||
applicationId = "org.neslite.app"
|
||||
minSdk = 28
|
||||
targetSdk = 36
|
||||
versionCode = 1
|
||||
versionName = "0.0.1-dev"
|
||||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||
|
||||
ndk {
|
||||
abiFilters += "arm64-v8a"
|
||||
}
|
||||
|
||||
externalNativeBuild {
|
||||
cmake {
|
||||
cppFlags += listOf("-std=c++20", "-Wall", "-Wextra", "-Werror")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
debug {
|
||||
applicationIdSuffix = ".debug"
|
||||
versionNameSuffix = "-debug"
|
||||
}
|
||||
release {
|
||||
isMinifyEnabled = false
|
||||
proguardFiles(
|
||||
getDefaultProguardFile("proguard-android-optimize.txt"),
|
||||
"proguard-rules.pro",
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
externalNativeBuild {
|
||||
cmake {
|
||||
path = file("src/main/cpp/CMakeLists.txt")
|
||||
version = "3.22.1"
|
||||
}
|
||||
}
|
||||
|
||||
packaging {
|
||||
jniLibs {
|
||||
useLegacyPackaging = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
kotlin {
|
||||
jvmToolchain(17)
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(libs.androidx.core.ktx)
|
||||
implementation(libs.androidx.activity.ktx)
|
||||
|
||||
testImplementation(libs.junit)
|
||||
androidTestImplementation(libs.androidx.junit)
|
||||
androidTestImplementation(libs.androidx.espresso.core)
|
||||
}
|
||||
Vendored
+1
@@ -0,0 +1 @@
|
||||
# M0 does not add application-specific shrinker rules.
|
||||
@@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<application
|
||||
android:allowBackup="false"
|
||||
android:label="@string/app_name"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/Theme.NESLite">
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:exported="true"
|
||||
android:screenOrientation="unspecified">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
</application>
|
||||
</manifest>
|
||||
@@ -0,0 +1,38 @@
|
||||
cmake_minimum_required(VERSION 3.22.1)
|
||||
project(neslite_jni LANGUAGES CXX)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 20)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
set(CMAKE_CXX_EXTENSIONS OFF)
|
||||
|
||||
set(NESLITE_COMMON_SOURCES
|
||||
native_smoke.cpp
|
||||
)
|
||||
|
||||
function(neslite_enable_strict_warnings target)
|
||||
if(MSVC)
|
||||
target_compile_options(${target} PRIVATE /W4 /WX)
|
||||
else()
|
||||
target_compile_options(${target} PRIVATE -Wall -Wextra -Werror)
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
if(ANDROID)
|
||||
add_library(neslite_jni SHARED
|
||||
jni_bridge.cpp
|
||||
${NESLITE_COMMON_SOURCES}
|
||||
)
|
||||
neslite_enable_strict_warnings(neslite_jni)
|
||||
|
||||
find_library(log-lib log)
|
||||
target_link_libraries(neslite_jni PRIVATE ${log-lib})
|
||||
else()
|
||||
enable_testing()
|
||||
add_executable(neslite_native_smoke_test
|
||||
tests/native_smoke_test.cpp
|
||||
${NESLITE_COMMON_SOURCES}
|
||||
)
|
||||
target_include_directories(neslite_native_smoke_test PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
neslite_enable_strict_warnings(neslite_native_smoke_test)
|
||||
add_test(NAME neslite_native_smoke_test COMMAND neslite_native_smoke_test)
|
||||
endif()
|
||||
@@ -0,0 +1,11 @@
|
||||
#include <jni.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "native_smoke.h"
|
||||
|
||||
extern "C" JNIEXPORT jstring JNICALL
|
||||
Java_org_neslite_app_NativeBridge_buildInfo(JNIEnv* env, jclass) {
|
||||
const std::string info = "native protocol v" + std::to_string(neslite::native_protocol_version());
|
||||
return env->NewStringUTF(info.c_str());
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
#include "native_smoke.h"
|
||||
|
||||
namespace neslite {
|
||||
|
||||
int native_protocol_version() {
|
||||
return kNativeProtocolVersion;
|
||||
}
|
||||
|
||||
} // namespace neslite
|
||||
@@ -0,0 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
namespace neslite {
|
||||
|
||||
constexpr int kNativeProtocolVersion = 1;
|
||||
int native_protocol_version();
|
||||
|
||||
} // namespace neslite
|
||||
@@ -0,0 +1,5 @@
|
||||
#include "native_smoke.h"
|
||||
|
||||
int main() {
|
||||
return neslite::native_protocol_version() == neslite::kNativeProtocolVersion ? 0 : 1;
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package org.neslite.app
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.Gravity
|
||||
import android.widget.LinearLayout
|
||||
import android.widget.TextView
|
||||
import androidx.activity.ComponentActivity
|
||||
|
||||
/** M0 骨架页:证明 Kotlin/View 与 JNI 已连通。M1 会将它替换为诊断页面。 */
|
||||
class MainActivity : ComponentActivity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
val nativeInfo = runCatching { NativeBridge.buildInfo() }
|
||||
.getOrElse { "JNI unavailable: ${it.javaClass.simpleName}" }
|
||||
|
||||
setContentView(
|
||||
LinearLayout(this).apply {
|
||||
gravity = Gravity.CENTER
|
||||
addView(
|
||||
TextView(context).apply {
|
||||
text = getString(R.string.bootstrap_status, nativeInfo)
|
||||
textSize = 18f
|
||||
setPadding(48, 48, 48, 48)
|
||||
},
|
||||
)
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package org.neslite.app
|
||||
|
||||
/** JNI boundary. M0 deliberately exposes a build marker, not emulator control. */
|
||||
object NativeBridge {
|
||||
init {
|
||||
System.loadLibrary("neslite_jni")
|
||||
}
|
||||
|
||||
external fun buildInfo(): String
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
<resources>
|
||||
<string name="app_name">NESLite</string>
|
||||
<string name="bootstrap_status">NESLite M0 baseline\n%s</string>
|
||||
</resources>
|
||||
@@ -0,0 +1,7 @@
|
||||
<resources>
|
||||
<style name="Theme.NESLite" parent="android:style/Theme.Material.Light.NoActionBar">
|
||||
<item name="android:colorAccent">#5E35B1</item>
|
||||
<item name="android:navigationBarColor">#FFFFFF</item>
|
||||
<item name="android:windowLightStatusBar">true</item>
|
||||
</style>
|
||||
</resources>
|
||||
@@ -0,0 +1,12 @@
|
||||
package org.neslite.app
|
||||
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Test
|
||||
|
||||
class BuildIdentityTest {
|
||||
@Test
|
||||
fun debugBuildUsesTheDocumentedIdentity() {
|
||||
assertEquals("org.neslite.app.debug", BuildConfig.APPLICATION_ID)
|
||||
assertEquals("0.0.1-dev-debug", BuildConfig.VERSION_NAME)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user