build.gradle 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. import java.security.MessageDigest
  2. import java.security.NoSuchAlgorithmException
  3. buildscript {
  4. dependencies {
  5. classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.0'
  6. }
  7. }
  8. group 'com.beswell.sensor'
  9. version '1.0-SNAPSHOT'
  10. buildscript {
  11. ext.kotlin_version = '1.8.0'
  12. repositories {
  13. google()
  14. mavenCentral()
  15. }
  16. dependencies {
  17. classpath 'com.android.tools.build:gradle:7.4.2'
  18. classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
  19. }
  20. }
  21. String localMavenPath = project.mkdir("build").absolutePath
  22. rootProject.allprojects {
  23. repositories {
  24. google()
  25. mavenCentral()
  26. maven { url "file://$localMavenPath" }
  27. }
  28. }
  29. apply plugin: 'com.android.library'
  30. apply plugin: 'kotlin-android'
  31. android {
  32. compileSdkVersion 33
  33. compileOptions {
  34. sourceCompatibility JavaVersion.VERSION_1_8
  35. targetCompatibility JavaVersion.VERSION_1_8
  36. }
  37. kotlinOptions {
  38. jvmTarget = '1.8'
  39. }
  40. sourceSets {
  41. main{
  42. java.srcDirs += 'src/main/kotlin'
  43. }
  44. }
  45. defaultConfig {
  46. minSdkVersion 21
  47. ndk {
  48. abiFilters "armeabi-v7a", "arm64-v8a"
  49. }
  50. }
  51. }
  52. dependencies {
  53. implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4'
  54. // implementation project(path: ':local_repo:chileaf_wear')
  55. // implementation(files("libs/chileaf_wear_sdk_2.0.5.aar"))
  56. // implementation fileTree(dir: 'libs', include: ['*.jar'])
  57. // implementation (name: 'chileaf_wear_sdk_x.x.x', ext: 'aar')
  58. }
  59. String aarPath = localMavenPath
  60. task useAar {
  61. File file = project.file("libs")
  62. if (file.exists() && file.isDirectory()) {
  63. file.listFiles(new FileFilter() {
  64. @Override
  65. boolean accept(File pathname) {
  66. return pathname.name.endsWith(".aar")
  67. }
  68. }).each { item ->
  69. String aarName = item.name.substring(0, item.name.length() - 4)
  70. String[] aarInfo = aarName.split("-")
  71. String sha1 = getFileSha1(item)
  72. String md5 = getFileMD5(item)
  73. println("aar: " + aarInfo + " file sha1:" + sha1 + " md5:" + md5)
  74. String fromStr = item.path
  75. String intoStr = aarPath + "/" + aarInfo[0].replace(".", "/") + "/" + aarInfo[1] + "/" + aarInfo[2]
  76. String newName = aarInfo[1] + "-" + aarInfo[2] + ".aar"
  77. project.copy {
  78. from fromStr
  79. into intoStr
  80. rename(item.name, newName)
  81. }
  82. project.file(intoStr + "/" + newName + ".md5").write(md5)
  83. project.file(intoStr + "/" + newName + ".sha1").write(sha1)
  84. String pomPath = intoStr + "/" + newName.substring(0, newName.length() - 4) + ".pom"
  85. project.file(pomPath).write(createPomStr(aarInfo[0], aarInfo[1], aarInfo[2]))
  86. project.file(pomPath + ".md5").write(getFileMD5(project.file(pomPath)))
  87. project.file(pomPath + ".sha1").write(getFileSha1(project.file(pomPath)))
  88. String metadataPath = project.file(intoStr).getParentFile().path + "/maven-metadata.xml"
  89. project.file(metadataPath).write(createMetadataStr(aarInfo[0], aarInfo[1], aarInfo[2]))
  90. project.file(metadataPath + ".md5").write(getFileMD5(project.file(metadataPath)))
  91. project.file(metadataPath + ".sha1").write(getFileSha1(project.file(metadataPath)))
  92. dependencies {
  93. implementation "${aarInfo[0]}:${aarInfo[1]}:${aarInfo[2]}"
  94. }
  95. }
  96. }
  97. }
  98. public static String createMetadataStr(String groupId, String artifactId, String version) {
  99. return "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
  100. "<metadata>\n" +
  101. " <groupId>$groupId</groupId>\n" +
  102. " <artifactId>$artifactId</artifactId>\n" +
  103. " <versioning>\n" +
  104. " <release>$version</release>\n" +
  105. " <versions>\n" +
  106. " <version>$version</version>\n" +
  107. " </versions>\n" +
  108. " <lastUpdated>${new Date().format('yyyyMMdd')}000000</lastUpdated>\n" +
  109. " </versioning>\n" +
  110. "</metadata>\n"
  111. }
  112. public static String createPomStr(String groupId, String artifactId, String version) {
  113. return "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
  114. "<project xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd\" xmlns=\"http://maven.apache.org/POM/4.0.0\"\n" +
  115. " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n" +
  116. " <modelVersion>4.0.0</modelVersion>\n" +
  117. " <groupId>$groupId</groupId>\n" +
  118. " <artifactId>$artifactId</artifactId>\n" +
  119. " <version>$version</version>\n" +
  120. " <packaging>aar</packaging>\n" +
  121. "</project>\n"
  122. }
  123. public static String getFileSha1(File file) {
  124. FileInputStream input = null;
  125. try {
  126. input = new FileInputStream(file);
  127. MessageDigest digest = MessageDigest.getInstance("SHA-1");
  128. byte[] buffer = new byte[1024 * 1024 * 10];
  129. int len = 0;
  130. while ((len = input.read(buffer)) > 0) {
  131. digest.update(buffer, 0, len);
  132. }
  133. String sha1 = new BigInteger(1, digest.digest()).toString(16);
  134. int length = 40 - sha1.length();
  135. if (length > 0) {
  136. for (int i = 0; i < length; i++) {
  137. sha1 = "0" + sha1;
  138. }
  139. }
  140. return sha1;
  141. }
  142. catch (IOException e) {
  143. System.out.println(e);
  144. }
  145. catch (NoSuchAlgorithmException e) {
  146. System.out.println(e);
  147. }
  148. finally {
  149. try {
  150. if (input != null) {
  151. input.close();
  152. }
  153. }
  154. catch (IOException e) {
  155. System.out.println(e);
  156. }
  157. }
  158. }
  159. public static String getFileMD5(File file) {
  160. FileInputStream input = null;
  161. try {
  162. input = new FileInputStream(file);
  163. MessageDigest digest = MessageDigest.getInstance("MD5");
  164. byte[] buffer = new byte[1024 * 1024 * 10];
  165. int len = 0;
  166. while ((len = input.read(buffer)) > 0) {
  167. digest.update(buffer, 0, len);
  168. }
  169. String md5 = new BigInteger(1, digest.digest()).toString(16);
  170. int length = 32 - md5.length();
  171. if (length > 0) {
  172. for (int i = 0; i < length; i++) {
  173. md5 = "0" + md5;
  174. }
  175. }
  176. return md5;
  177. }
  178. catch (IOException e) {
  179. System.out.println(e);
  180. }
  181. catch (NoSuchAlgorithmException e) {
  182. System.out.println(e);
  183. }
  184. finally {
  185. try {
  186. if (input != null) {
  187. input.close();
  188. }
  189. }
  190. catch (IOException e) {
  191. System.out.println(e);
  192. }
  193. }
  194. }