Explorar el Código

项目aar包配置

王育民 hace 5 años
padre
commit
dab8e68a94
Se han modificado 6 ficheros con 88 adiciones y 1 borrados
  1. 24 1
      app/build.gradle
  2. 27 0
      build.gradle
  3. 15 0
      gradle.properties
  4. 6 0
      gradle/wrapper/gradle-wrapper.properties
  5. 15 0
      serialport/build.gradle
  6. 1 0
      settings.gradle

+ 24 - 1
app/build.gradle

@@ -16,6 +16,29 @@ android {
             proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
         }
     }
+
+    sourceSets {
+        main {
+            assets.srcDirs = ['assets']
+            jniLibs.srcDirs = ['libs']
+        }
+    }
+
+    // 指定项目编码方式
+    compileOptions.encoding = "UTF-8"
+
+    // 指定编译版本
+    compileOptions {
+        sourceCompatibility JavaVersion.VERSION_1_8
+        targetCompatibility JavaVersion.VERSION_1_8
+    }
+
+    // 指定本地仓库
+    repositories {
+        flatDir {
+            dirs 'libs'
+        }
+    }
 }
 
 dependencies {
@@ -25,5 +48,5 @@ dependencies {
     testImplementation 'junit:junit:4.12'
     androidTestImplementation 'com.android.support.test:runner:1.0.2'
     androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
-    implementation project(':serialport')
+    implementation(name: 'serialport-release', ext: 'aar')
 }

+ 27 - 0
build.gradle

@@ -0,0 +1,27 @@
+// Top-level build file where you can add configuration options common to all sub-projects/modules.
+
+buildscript {
+    repositories {
+        google()
+        jcenter()
+        
+    }
+    dependencies {
+        classpath 'com.android.tools.build:gradle:3.4.2'
+        
+        // NOTE: Do not place your application dependencies here; they belong
+        // in the individual module build.gradle files
+    }
+}
+
+allprojects {
+    repositories {
+        google()
+        jcenter()
+        
+    }
+}
+
+task clean(type: Delete) {
+    delete rootProject.buildDir
+}

+ 15 - 0
gradle.properties

@@ -0,0 +1,15 @@
+# Project-wide Gradle settings.
+# IDE (e.g. Android Studio) users:
+# Gradle settings configured through the IDE *will override*
+# any settings specified in this file.
+# For more details on how to configure your build environment visit
+# http://www.gradle.org/docs/current/userguide/build_environment.html
+# Specifies the JVM arguments used for the daemon process.
+# The setting is particularly useful for tweaking memory settings.
+org.gradle.jvmargs=-Xmx1536m
+# When configured, Gradle will run in incubating parallel mode.
+# This option should only be used with decoupled projects. More details, visit
+# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
+# org.gradle.parallel=true
+
+

+ 6 - 0
gradle/wrapper/gradle-wrapper.properties

@@ -0,0 +1,6 @@
+#Wed Jul 17 15:41:06 CST 2019
+distributionBase=GRADLE_USER_HOME
+distributionPath=wrapper/dists
+zipStoreBase=GRADLE_USER_HOME
+zipStorePath=wrapper/dists
+distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip

+ 15 - 0
serialport/build.gradle

@@ -43,3 +43,18 @@ dependencies {
         exclude group: 'com.android.support', module: 'support-annotations'
     })
 }
+
+// 生成 jar 包并修改名字
+task makeJar(type: Copy) {
+    // 删除已经存在的 jar 包,如果有的话
+    delete 'build/libs/SerialPort.jar'
+    // 从该目录下加载要打包的文件,注意文件夹名称有可能为 default,也可能是 release
+    from('build/intermediates/bundles/release/')
+    // jar 包的保存目录
+    into('build/libs/')
+    // 设置过滤,只打包classes文件
+    include('classes.jar')
+    // 重命名 jar 包
+    rename('classes.jar', 'SerialPort.jar')
+}
+makeJar.dependsOn(build)

+ 1 - 0
settings.gradle

@@ -0,0 +1 @@
+include ':app', ':serialport'