|
| 1 | +--- |
| 2 | +title: Gradle解析器 |
| 3 | +--- |
| 4 | + |
| 5 | +# 说明 |
| 6 | + |
| 7 | +:::warning **注意** |
| 8 | + |
| 9 | +由于Gradle体量过大,目前只能进行解析,并不能编译运行 |
| 10 | + |
| 11 | +::: |
| 12 | + |
| 13 | + |
| 14 | +### android-ndkVersion |
| 15 | +- `path` CMakeLists.txt路径 |
| 16 | +- `version` Cmake版 |
| 17 | +- `ndkVersion` NDK版本 |
| 18 | +- `cppFlags` 编译器参数 |
| 19 | +- `abiFilters` abi过滤 |
| 20 | +- `arguments` |
| 21 | + |
| 22 | +### android-externalNativeBuild-cmake |
| 23 | +::: tip |
| 24 | + 和**android-ndkVersion**一样 |
| 25 | +::: |
| 26 | + |
| 27 | + |
| 28 | +### android-compileOptions |
| 29 | + |
| 30 | +:::tip **注意** |
| 31 | + |
| 32 | +需要打开**ecj模式**(设置 -> 实验室 -> ecj),才能设置Java语法版本 |
| 33 | + |
| 34 | +最高支持Java23,但是想在安卓上运行是不太可能的 |
| 35 | + |
| 36 | +::: |
| 37 | + |
| 38 | +::: details |
| 39 | +```java{2,3} |
| 40 | +compileOptions { |
| 41 | + sourceCompatibility JavaVersion.VERSION_17 |
| 42 | + targetCompatibility JavaVersion.VERSION_17 |
| 43 | +} |
| 44 | +``` |
| 45 | +::: |
| 46 | + |
| 47 | +### android-signingConfigs |
| 48 | + |
| 49 | +:::tip **注意** |
| 50 | + |
| 51 | +**storeFile**可以输入绝对和相对路径 |
| 52 | + |
| 53 | +可以到设置里面创建自定义的密匙文件 |
| 54 | + |
| 55 | +::: |
| 56 | + |
| 57 | +::: details |
| 58 | +```java{3-6} |
| 59 | +signingConfigs{ |
| 60 | + debug{ |
| 61 | + keyAlias "androiddebug" |
| 62 | + keyPassword "123789456" |
| 63 | + storePassword "123789456" |
| 64 | + storeFile file("app-debug.jks") |
| 65 | + } |
| 66 | +} |
| 67 | +``` |
| 68 | +::: |
| 69 | + |
| 70 | + |
| 71 | +### android-buildTypes-release |
| 72 | + |
| 73 | +:::tip **注意** |
| 74 | + |
| 75 | +仅支持配置release(但不分是否是 release) |
| 76 | + |
| 77 | +::: |
| 78 | + |
| 79 | +- 资源混淆 |
| 80 | + |
| 81 | + `shrinkResources` 输入值为 **布尔值** |
| 82 | + |
| 83 | + |
| 84 | +- 代码混淆 **增量构建会失效** |
| 85 | + |
| 86 | + `minifyEnabled` 输入值为 **布尔值** |
| 87 | + |
| 88 | +- 代码混淆配置文件 |
| 89 | + |
| 90 | + `proguardFiles `默认为 `getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'` |
| 91 | + |
| 92 | + |
| 93 | + |
| 94 | +### android-buildFeatures |
| 95 | + |
| 96 | +- 启用viewBinding |
| 97 | + |
| 98 | + `viewBinding` true则启用 |
| 99 | + |
| 100 | +- ~~启用dataBinding~~ |
| 101 | + |
| 102 | + ~~`dataBinding` true则启用~~ |
| 103 | + |
| 104 | + 由于并不完整,目前已经废弃了 |
| 105 | + |
| 106 | +- 启用androidx |
| 107 | + |
| 108 | + `useAndroidx`,默认为`true` |
| 109 | + |
| 110 | + 但Gradle 8.5不支持此写法 |
| 111 | + |
| 112 | + 如若使用Gradle请更改`gradle.properties`文件 `android.useAndroidX` |
| 113 | + |
| 114 | +### dependencies |
| 115 | + |
| 116 | +::: tip |
| 117 | + |
| 118 | +支持打包jar根目录classes{N}.dex文件 |
| 119 | + |
| 120 | +但是Gradle不支持打包classes{N}.dex |
| 121 | + |
| 122 | +::: |
| 123 | + |
| 124 | +支持以下语法 |
| 125 | +- `implementation` 不传递依赖 |
| 126 | +- `api` 传递依赖 |
| 127 | +- `compile` 传递依赖 |
| 128 | +- `runtimeOnly` 仅运行时 |
| 129 | +- `compileOnly` 仅编译 |
| 130 | +- `exclude` 排除某个包 |
| 131 | +- `wearApp` 手表应用 |
| 132 | +- `natives`,`libgdxNatives` libgdx适配 |
| 133 | +- ~~`coreLibraryDesugaring`~~ l8脱糖 |
| 134 | + |
| 135 | + |
| 136 | + |
0 commit comments