Skip to content

Commit

Permalink
Merge pull request #57 from freesith/master
Browse files Browse the repository at this point in the history
适配build.gradle.kts文件的namespace格式
  • Loading branch information
liujingxing committed Oct 21, 2023
2 parents 57cf2e4 + da70320 commit 96b0a4a
Show file tree
Hide file tree
Showing 12 changed files with 120 additions and 2 deletions.
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ android {
dependencies {

implementation project(":base")
implementation project(":kts_test")
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.4.2'
implementation 'com.google.android.material:material:1.4.0'
Expand Down
6 changes: 4 additions & 2 deletions app/xmlclassguard.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ xmlClassGuard {
mappingFile = file("xml-class-mapping.txt")
//更改manifest里package属性
packageChange = ["com.ljx.example": "ab.cd",
"com.ljx.base" : "ggg.kkk"]
"com.ljx.base" : "ggg.kkk",
"com.ljx.kts" : "ff.dd"]
//移动目录,支持同时移动多个目录
moveDir = ["com.ljx.example": "ef.gh",
"com.ljx.base" : "zzzz.hhhh"]
"com.ljx.base" : "zzzz.hhhh",
"com.ljx.kts" : "ddd.xxx"]
}
1 change: 1 addition & 0 deletions kts_test/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
42 changes: 42 additions & 0 deletions kts_test/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
plugins {
id("com.android.library")
id("org.jetbrains.kotlin.android")
}

android {
namespace = "com.ljx.kts"
compileSdk = 33

defaultConfig {
minSdk = 21

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles("consumer-rules.pro")
}

buildTypes {
release {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "1.8"
}
}

dependencies {
implementation("androidx.core:core-ktx:1.7.0")
implementation("androidx.appcompat:appcompat:1.4.2")
implementation("com.google.android.material:material:1.4.0")
testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test.ext:junit:1.1.3")
androidTestImplementation("androidx.test.espresso:espresso-core:3.4.0")
}
Empty file added kts_test/consumer-rules.pro
Empty file.
21 changes: 21 additions & 0 deletions kts_test/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.ljx.kts

import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4

import org.junit.Test
import org.junit.runner.RunWith

import org.junit.Assert.*

/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("com.ljx.kts.test", appContext.packageName)
}
}
4 changes: 4 additions & 0 deletions kts_test/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.ljx.kts">

</manifest>
4 changes: 4 additions & 0 deletions kts_test/src/main/java/com/ljx/kts/KtsTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.ljx.kts

class KtsTest {
}
17 changes: 17 additions & 0 deletions kts_test/src/test/java/com/ljx/kts/ExampleUnitTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.ljx.kts

import org.junit.Test

import org.junit.Assert.*

/**
* Example local unit test, which will execute on the development machine (host).
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
class ExampleUnitTest {
@Test
fun addition_isCorrect() {
assertEquals(4, 2 + 2)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ open class PackageChangeTask @Inject constructor(
private fun File.modifyBuildGradleFile(oldPackage: String, newPackage: String) {
readText()
.replace("namespace\\s+['\"]${oldPackage}['\"]".toRegex(), "namespace '$newPackage'")
.replace("namespace\\s*=\\s*['\"]${oldPackage}['\"]".toRegex(), """namespace = "$newPackage"""")
.let { writeText(it) }
}

Expand Down
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ rootProject.name = "XmlClassGuard"
include ':app'
include ':plugin'
include ':base'
include ':kts_test'

0 comments on commit 96b0a4a

Please sign in to comment.