build.gradle 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. plugins {
  2. id 'com.android.application'
  3. id 'org.jetbrains.kotlin.android'
  4. }
  5. android {
  6. namespace 'com.example.myapp' // AGP 8.0+ 强制要求命名空间
  7. // 建议使用 34 或 35,AGP 9.0 支持最高 36
  8. compileSdk = 35
  9. defaultConfig {
  10. applicationId "com.example.myapp"
  11. minSdk = 21
  12. targetSdk = 35 // 建议与 compileSdk 保持一致
  13. versionCode 1
  14. versionName "1.0"
  15. testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
  16. }
  17. buildTypes {
  18. release {
  19. minifyEnabled false
  20. proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
  21. }
  22. }
  23. // 编译选项:AGP 9.0 + Gradle 9.1 推荐使用 Java 17 或 21
  24. compileOptions {
  25. sourceCompatibility = JavaVersion.VERSION_21
  26. targetCompatibility = JavaVersion.VERSION_21
  27. }
  28. kotlinOptions {
  29. jvmTarget = '21'
  30. }
  31. // 可选:启用构建特征预览 (如果需要使用新特性)
  32. // buildFeatures {
  33. // viewBinding true
  34. // }
  35. }
  36. dependencies {
  37. // Kotlin 标准库通常由插件自动引入,无需显式声明,除非需要特定版本
  38. // implementation "org.jetbrains.kotlin:kotlin-stdlib:2.0.21"
  39. implementation 'androidx.core:core-ktx:1.15.0' // 使用较新版本以适配 SDK 35
  40. implementation 'androidx.appcompat:appcompat:1.7.0'
  41. implementation 'com.google.android.material:material:1.12.0'
  42. testImplementation 'junit:junit:4.13.2'
  43. androidTestImplementation 'androidx.test.ext:junit:1.2.1'
  44. androidTestImplementation 'androidx.test.espresso:espresso-core:3.6.1'
  45. }