import java.security.MessageDigest import java.security.NoSuchAlgorithmException buildscript { dependencies { classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.0' } } group 'com.beswell.sensor' version '1.0-SNAPSHOT' buildscript { ext.kotlin_version = '1.8.0' repositories { google() mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:7.4.2' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } } String localMavenPath = project.mkdir("build").absolutePath rootProject.allprojects { repositories { google() mavenCentral() maven { url "file://$localMavenPath" } } } apply plugin: 'com.android.library' apply plugin: 'kotlin-android' android { compileSdkVersion 33 compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } kotlinOptions { jvmTarget = '1.8' } sourceSets { main{ java.srcDirs += 'src/main/kotlin' } } defaultConfig { minSdkVersion 21 ndk { abiFilters "armeabi-v7a", "arm64-v8a" } } } dependencies { implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4' // implementation project(path: ':local_repo:chileaf_wear') // implementation(files("libs/chileaf_wear_sdk_2.0.5.aar")) // implementation fileTree(dir: 'libs', include: ['*.jar']) // implementation (name: 'chileaf_wear_sdk_x.x.x', ext: 'aar') } String aarPath = localMavenPath task useAar { File file = project.file("libs") if (file.exists() && file.isDirectory()) { file.listFiles(new FileFilter() { @Override boolean accept(File pathname) { return pathname.name.endsWith(".aar") } }).each { item -> String aarName = item.name.substring(0, item.name.length() - 4) String[] aarInfo = aarName.split("-") String sha1 = getFileSha1(item) String md5 = getFileMD5(item) println("aar: " + aarInfo + " file sha1:" + sha1 + " md5:" + md5) String fromStr = item.path String intoStr = aarPath + "/" + aarInfo[0].replace(".", "/") + "/" + aarInfo[1] + "/" + aarInfo[2] String newName = aarInfo[1] + "-" + aarInfo[2] + ".aar" project.copy { from fromStr into intoStr rename(item.name, newName) } project.file(intoStr + "/" + newName + ".md5").write(md5) project.file(intoStr + "/" + newName + ".sha1").write(sha1) String pomPath = intoStr + "/" + newName.substring(0, newName.length() - 4) + ".pom" project.file(pomPath).write(createPomStr(aarInfo[0], aarInfo[1], aarInfo[2])) project.file(pomPath + ".md5").write(getFileMD5(project.file(pomPath))) project.file(pomPath + ".sha1").write(getFileSha1(project.file(pomPath))) String metadataPath = project.file(intoStr).getParentFile().path + "/maven-metadata.xml" project.file(metadataPath).write(createMetadataStr(aarInfo[0], aarInfo[1], aarInfo[2])) project.file(metadataPath + ".md5").write(getFileMD5(project.file(metadataPath))) project.file(metadataPath + ".sha1").write(getFileSha1(project.file(metadataPath))) dependencies { implementation "${aarInfo[0]}:${aarInfo[1]}:${aarInfo[2]}" } } } } public static String createMetadataStr(String groupId, String artifactId, String version) { return "\n" + "\n" + " $groupId\n" + " $artifactId\n" + " \n" + " $version\n" + " \n" + " $version\n" + " \n" + " ${new Date().format('yyyyMMdd')}000000\n" + " \n" + "\n" } public static String createPomStr(String groupId, String artifactId, String version) { return "\n" + "\n" + " 4.0.0\n" + " $groupId\n" + " $artifactId\n" + " $version\n" + " aar\n" + "\n" } public static String getFileSha1(File file) { FileInputStream input = null; try { input = new FileInputStream(file); MessageDigest digest = MessageDigest.getInstance("SHA-1"); byte[] buffer = new byte[1024 * 1024 * 10]; int len = 0; while ((len = input.read(buffer)) > 0) { digest.update(buffer, 0, len); } String sha1 = new BigInteger(1, digest.digest()).toString(16); int length = 40 - sha1.length(); if (length > 0) { for (int i = 0; i < length; i++) { sha1 = "0" + sha1; } } return sha1; } catch (IOException e) { System.out.println(e); } catch (NoSuchAlgorithmException e) { System.out.println(e); } finally { try { if (input != null) { input.close(); } } catch (IOException e) { System.out.println(e); } } } public static String getFileMD5(File file) { FileInputStream input = null; try { input = new FileInputStream(file); MessageDigest digest = MessageDigest.getInstance("MD5"); byte[] buffer = new byte[1024 * 1024 * 10]; int len = 0; while ((len = input.read(buffer)) > 0) { digest.update(buffer, 0, len); } String md5 = new BigInteger(1, digest.digest()).toString(16); int length = 32 - md5.length(); if (length > 0) { for (int i = 0; i < length; i++) { md5 = "0" + md5; } } return md5; } catch (IOException e) { System.out.println(e); } catch (NoSuchAlgorithmException e) { System.out.println(e); } finally { try { if (input != null) { input.close(); } } catch (IOException e) { System.out.println(e); } } }