├── asm-demo ├── app │ ├── .gitignore │ ├── src │ │ ├── main │ │ │ ├── res │ │ │ │ ├── values │ │ │ │ │ ├── strings.xml │ │ │ │ │ ├── colors.xml │ │ │ │ │ └── styles.xml │ │ │ │ ├── mipmap-hdpi │ │ │ │ │ ├── ic_launcher.png │ │ │ │ │ └── ic_launcher_round.png │ │ │ │ ├── mipmap-mdpi │ │ │ │ │ ├── ic_launcher.png │ │ │ │ │ └── ic_launcher_round.png │ │ │ │ ├── mipmap-xhdpi │ │ │ │ │ ├── ic_launcher.png │ │ │ │ │ └── ic_launcher_round.png │ │ │ │ ├── mipmap-xxhdpi │ │ │ │ │ ├── ic_launcher.png │ │ │ │ │ └── ic_launcher_round.png │ │ │ │ ├── mipmap-xxxhdpi │ │ │ │ │ ├── ic_launcher.png │ │ │ │ │ └── ic_launcher_round.png │ │ │ │ ├── mipmap-anydpi-v26 │ │ │ │ │ ├── ic_launcher.xml │ │ │ │ │ └── ic_launcher_round.xml │ │ │ │ ├── layout │ │ │ │ │ └── activity_main.xml │ │ │ │ ├── drawable-v24 │ │ │ │ │ └── ic_launcher_foreground.xml │ │ │ │ └── drawable │ │ │ │ │ └── ic_launcher_background.xml │ │ │ ├── java │ │ │ │ └── com │ │ │ │ │ └── jeremyliao │ │ │ │ │ └── android │ │ │ │ │ └── asm │ │ │ │ │ ├── TestTarget.java │ │ │ │ │ ├── PrintLogDemo.java │ │ │ │ │ └── MainActivity.java │ │ │ └── AndroidManifest.xml │ │ ├── test │ │ │ └── java │ │ │ │ └── com │ │ │ │ └── jeremyliao │ │ │ │ └── android │ │ │ │ └── asm │ │ │ │ └── ExampleUnitTest.java │ │ └── androidTest │ │ │ └── java │ │ │ └── com │ │ │ └── jeremyliao │ │ │ └── android │ │ │ └── asm │ │ │ └── ExampleInstrumentedTest.java │ ├── proguard-rules.pro │ └── build.gradle ├── base │ ├── .gitignore │ ├── build.gradle │ └── src │ │ └── main │ │ └── java │ │ └── com │ │ └── jeremyliao │ │ └── android │ │ └── base │ │ └── annotation │ │ └── PrintLog.java ├── plugin │ ├── .gitignore │ ├── src │ │ └── main │ │ │ ├── resources │ │ │ └── META-INF │ │ │ │ └── gradle-plugins │ │ │ │ └── asm-plugin.properties │ │ │ ├── java │ │ │ └── com │ │ │ │ └── jeremyliao │ │ │ │ └── android │ │ │ │ ├── base │ │ │ │ └── annotation │ │ │ │ │ └── PrintLog.java │ │ │ │ └── plugin │ │ │ │ ├── OnCreateMethodVisitor.java │ │ │ │ ├── OnDestroyMethodVisitor.java │ │ │ │ ├── TestClassVisitor.java │ │ │ │ └── PrintLogClassVisitor.java │ │ │ └── groovy │ │ │ └── com │ │ │ └── jeremyliao │ │ │ └── android │ │ │ └── plugin │ │ │ ├── PrintLogPlugin.groovy │ │ │ └── transform │ │ │ └── PrintLogTransform.groovy │ └── build.gradle ├── settings.gradle ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── .gitignore ├── build.gradle ├── gradle.properties ├── gradlew.bat └── gradlew ├── aspectj-demo ├── apilib │ ├── consumer-rules.pro │ ├── .gitignore │ ├── src │ │ ├── main │ │ │ ├── res │ │ │ │ └── values │ │ │ │ │ └── strings.xml │ │ │ ├── AndroidManifest.xml │ │ │ └── java │ │ │ │ └── com │ │ │ │ └── jeremyliao │ │ │ │ └── android │ │ │ │ └── apilib │ │ │ │ ├── PrintLogDemo.java │ │ │ │ └── TestTarget.java │ │ ├── test │ │ │ └── java │ │ │ │ └── com │ │ │ │ └── jeremyliao │ │ │ │ └── android │ │ │ │ └── apilib │ │ │ │ └── ExampleUnitTest.java │ │ └── androidTest │ │ │ └── java │ │ │ └── com │ │ │ └── jeremyliao │ │ │ └── android │ │ │ └── apilib │ │ │ └── ExampleInstrumentedTest.java │ ├── proguard-rules.pro │ └── build.gradle ├── app │ ├── .gitignore │ ├── src │ │ ├── main │ │ │ ├── res │ │ │ │ ├── values │ │ │ │ │ ├── strings.xml │ │ │ │ │ ├── colors.xml │ │ │ │ │ └── styles.xml │ │ │ │ ├── mipmap-hdpi │ │ │ │ │ ├── ic_launcher.png │ │ │ │ │ └── ic_launcher_round.png │ │ │ │ ├── mipmap-mdpi │ │ │ │ │ ├── ic_launcher.png │ │ │ │ │ └── ic_launcher_round.png │ │ │ │ ├── mipmap-xhdpi │ │ │ │ │ ├── ic_launcher.png │ │ │ │ │ └── ic_launcher_round.png │ │ │ │ ├── mipmap-xxhdpi │ │ │ │ │ ├── ic_launcher.png │ │ │ │ │ └── ic_launcher_round.png │ │ │ │ ├── mipmap-xxxhdpi │ │ │ │ │ ├── ic_launcher.png │ │ │ │ │ └── ic_launcher_round.png │ │ │ │ ├── mipmap-anydpi-v26 │ │ │ │ │ ├── ic_launcher.xml │ │ │ │ │ └── ic_launcher_round.xml │ │ │ │ ├── layout │ │ │ │ │ └── activity_main.xml │ │ │ │ ├── drawable-v24 │ │ │ │ │ └── ic_launcher_foreground.xml │ │ │ │ └── drawable │ │ │ │ │ └── ic_launcher_background.xml │ │ │ ├── AndroidManifest.xml │ │ │ └── java │ │ │ │ └── com │ │ │ │ └── jeremyliao │ │ │ │ └── android │ │ │ │ └── aspectjdemo │ │ │ │ └── MainActivity.java │ │ ├── test │ │ │ └── java │ │ │ │ └── com │ │ │ │ └── jeremyliao │ │ │ │ └── android │ │ │ │ └── aspectjdemo │ │ │ │ └── ExampleUnitTest.java │ │ └── androidTest │ │ │ └── java │ │ │ └── com │ │ │ └── jeremyliao │ │ │ └── android │ │ │ └── aspectjdemo │ │ │ └── ExampleInstrumentedTest.java │ ├── proguard-rules.pro │ └── build.gradle ├── base │ ├── consumer-rules.pro │ ├── .gitignore │ ├── src │ │ └── main │ │ │ ├── res │ │ │ └── values │ │ │ │ └── strings.xml │ │ │ ├── AndroidManifest.xml │ │ │ └── java │ │ │ └── com │ │ │ └── jeremyliao │ │ │ └── android │ │ │ └── base │ │ │ ├── annotation │ │ │ ├── ExecutionTime.java │ │ │ ├── MethodControl.java │ │ │ └── PrintLog.java │ │ │ └── aspect │ │ │ ├── ExecutionTimeAspect.java │ │ │ ├── MethodControlAspect.java │ │ │ └── PrintLogAspect.java │ ├── build.gradle │ └── proguard-rules.pro ├── plugin │ ├── .gitignore │ ├── src │ │ └── main │ │ │ ├── resources │ │ │ └── META-INF │ │ │ │ └── gradle-plugins │ │ │ │ └── aspectj-plugin.properties │ │ │ └── groovy │ │ │ └── com │ │ │ └── jeremyliao │ │ │ └── android │ │ │ └── plugin │ │ │ └── AspectJPlugin.groovy │ └── build.gradle ├── settings.gradle ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── .gitignore ├── build.gradle ├── gradle.properties ├── gradlew.bat └── gradlew ├── javassist-demo ├── app │ ├── .gitignore │ ├── src │ │ ├── main │ │ │ ├── res │ │ │ │ ├── values │ │ │ │ │ ├── strings.xml │ │ │ │ │ ├── colors.xml │ │ │ │ │ └── styles.xml │ │ │ │ ├── mipmap-hdpi │ │ │ │ │ ├── ic_launcher.png │ │ │ │ │ └── ic_launcher_round.png │ │ │ │ ├── mipmap-mdpi │ │ │ │ │ ├── ic_launcher.png │ │ │ │ │ └── ic_launcher_round.png │ │ │ │ ├── mipmap-xhdpi │ │ │ │ │ ├── ic_launcher.png │ │ │ │ │ └── ic_launcher_round.png │ │ │ │ ├── mipmap-xxhdpi │ │ │ │ │ ├── ic_launcher.png │ │ │ │ │ └── ic_launcher_round.png │ │ │ │ ├── mipmap-xxxhdpi │ │ │ │ │ ├── ic_launcher.png │ │ │ │ │ └── ic_launcher_round.png │ │ │ │ ├── mipmap-anydpi-v26 │ │ │ │ │ ├── ic_launcher.xml │ │ │ │ │ └── ic_launcher_round.xml │ │ │ │ ├── layout │ │ │ │ │ └── activity_main.xml │ │ │ │ ├── drawable-v24 │ │ │ │ │ └── ic_launcher_foreground.xml │ │ │ │ └── drawable │ │ │ │ │ └── ic_launcher_background.xml │ │ │ ├── java │ │ │ │ └── com │ │ │ │ │ └── jeremyliao │ │ │ │ │ └── android │ │ │ │ │ └── javassist │ │ │ │ │ ├── MainActivity.java │ │ │ │ │ └── PrintLogDemo.java │ │ │ └── AndroidManifest.xml │ │ ├── test │ │ │ └── java │ │ │ │ └── com │ │ │ │ └── jeremyliao │ │ │ │ └── android │ │ │ │ └── javassist │ │ │ │ └── ExampleUnitTest.java │ │ └── androidTest │ │ │ └── java │ │ │ └── com │ │ │ └── jeremyliao │ │ │ └── android │ │ │ └── javassist │ │ │ └── ExampleInstrumentedTest.java │ ├── proguard-rules.pro │ └── build.gradle ├── base │ ├── .gitignore │ ├── build.gradle │ └── src │ │ └── main │ │ └── java │ │ └── com │ │ └── jeremyliao │ │ └── android │ │ └── base │ │ └── annotation │ │ └── PrintLog.java ├── plugin │ ├── .gitignore │ ├── src │ │ └── main │ │ │ ├── resources │ │ │ └── META-INF │ │ │ │ └── gradle-plugins │ │ │ │ └── javassist-plugin.properties │ │ │ ├── java │ │ │ └── com │ │ │ │ └── jeremyliao │ │ │ │ └── android │ │ │ │ ├── base │ │ │ │ └── annotation │ │ │ │ │ └── PrintLog.java │ │ │ │ └── plugin │ │ │ │ └── handler │ │ │ │ └── JavassistHandler.java │ │ │ └── groovy │ │ │ └── com │ │ │ └── jeremyliao │ │ │ └── android │ │ │ └── plugin │ │ │ ├── PrintLogPlugin.groovy │ │ │ └── transform │ │ │ └── PrintLogTransform.groovy │ └── build.gradle ├── settings.gradle ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── .gitignore ├── build.gradle ├── gradle.properties ├── gradlew.bat └── gradlew ├── android-gradle-study ├── app │ ├── .gitignore │ ├── gradle.properties │ ├── src │ │ └── main │ │ │ ├── res │ │ │ ├── values │ │ │ │ ├── strings.xml │ │ │ │ ├── colors.xml │ │ │ │ └── styles.xml │ │ │ ├── mipmap-hdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-mdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xxhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xxxhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-anydpi-v26 │ │ │ │ ├── ic_launcher.xml │ │ │ │ └── ic_launcher_round.xml │ │ │ ├── layout │ │ │ │ └── activity_main.xml │ │ │ ├── drawable-v24 │ │ │ │ └── ic_launcher_foreground.xml │ │ │ └── drawable │ │ │ │ └── ic_launcher_background.xml │ │ │ ├── java │ │ │ └── com │ │ │ │ └── jeremyliao │ │ │ │ └── gradle │ │ │ │ └── MainActivity.java │ │ │ └── AndroidManifest.xml │ ├── proguard-rules.pro │ └── build.gradle ├── compiler │ ├── .gitignore │ ├── build.gradle │ └── src │ │ └── main │ │ └── java │ │ └── com │ │ └── jeremyliao │ │ └── compiler │ │ └── AgsProcessor.java ├── plugin │ ├── .gitignore │ ├── src │ │ └── main │ │ │ ├── resources │ │ │ └── META-INF │ │ │ │ └── gradle-plugins │ │ │ │ ├── ags-java-plugin.properties │ │ │ │ ├── ags-groovy-plugin.properties │ │ │ │ ├── dependency-plugin.properties │ │ │ │ ├── classpath-plugin.properties │ │ │ │ └── property-read-plugin.properties │ │ │ ├── java │ │ │ └── com │ │ │ │ └── jeremyliao │ │ │ │ └── plugin │ │ │ │ ├── extension │ │ │ │ └── DemoExtension.java │ │ │ │ └── AgsJavaPlugin.java │ │ │ └── groovy │ │ │ └── com │ │ │ └── jeremyliao │ │ │ ├── plugin │ │ │ ├── PropertyReadPlugin.groovy │ │ │ ├── AgsGroovyPlugin.groovy │ │ │ ├── DynamicClasspathPlugin.groovy │ │ │ └── DependencyPlugin.groovy │ │ │ └── transform │ │ │ └── AgsTransform.groovy │ └── build.gradle ├── plugin1 │ ├── .gitignore │ ├── src │ │ └── main │ │ │ ├── resources │ │ │ └── META-INF │ │ │ │ └── gradle-plugins │ │ │ │ └── ags-test-plugin.properties │ │ │ └── groovy │ │ │ └── com │ │ │ └── jeremyliao │ │ │ └── plugin │ │ │ ├── AgsTestPlugin.groovy │ │ │ └── utils │ │ │ └── GradleUtils.groovy │ └── build.gradle ├── testlibrary │ ├── consumer-rules.pro │ ├── .gitignore │ ├── src │ │ ├── main │ │ │ ├── res │ │ │ │ └── values │ │ │ │ │ └── strings.xml │ │ │ └── AndroidManifest.xml │ │ └── test │ │ │ └── java │ │ │ └── com │ │ │ └── jeremyliao │ │ │ └── android │ │ │ └── testlibrary │ │ │ └── ExampleUnitTest.java │ ├── proguard-rules.pro │ └── build.gradle ├── white_list.prop ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── .gitignore ├── tools.gradle ├── groovy_test.gradle ├── settings.gradle ├── gradle.properties ├── build.gradle ├── gradlew.bat └── gradlew ├── LICENSE └── .gitignore /asm-demo/app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /asm-demo/base/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /asm-demo/plugin/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /aspectj-demo/apilib/consumer-rules.pro: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /aspectj-demo/app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /aspectj-demo/base/consumer-rules.pro: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /aspectj-demo/apilib/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /aspectj-demo/base/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /aspectj-demo/plugin/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /javassist-demo/app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /javassist-demo/base/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /javassist-demo/plugin/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /android-gradle-study/app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /android-gradle-study/compiler/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /android-gradle-study/plugin/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /android-gradle-study/plugin1/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /android-gradle-study/testlibrary/consumer-rules.pro: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /android-gradle-study/testlibrary/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /android-gradle-study/app/gradle.properties: -------------------------------------------------------------------------------- 1 | testProperty=hello -------------------------------------------------------------------------------- /asm-demo/settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app', ':plugin', ':base' 2 | rootProject.name='asm-demo' 3 | -------------------------------------------------------------------------------- /javassist-demo/settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app', ':base', ':plugin' 2 | rootProject.name='javassist-demo' 3 | -------------------------------------------------------------------------------- /aspectj-demo/settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app', ':base', ':plugin', ':apilib' 2 | rootProject.name='aspectj-demo' 3 | -------------------------------------------------------------------------------- /asm-demo/app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | asm-demo 3 | 4 | -------------------------------------------------------------------------------- /aspectj-demo/base/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | base 3 | 4 | -------------------------------------------------------------------------------- /aspectj-demo/apilib/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | apilib 3 | 4 | -------------------------------------------------------------------------------- /android-gradle-study/white_list.prop: -------------------------------------------------------------------------------- 1 | com.android.support:appcompat-v7:28.0.0 2 | com.android.support.constraint:constraint-layout:1.1.3 -------------------------------------------------------------------------------- /aspectj-demo/app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | aspectj-demo 3 | 4 | -------------------------------------------------------------------------------- /javassist-demo/app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | javassist-demo 3 | 4 | -------------------------------------------------------------------------------- /asm-demo/plugin/src/main/resources/META-INF/gradle-plugins/asm-plugin.properties: -------------------------------------------------------------------------------- 1 | implementation-class=com.jeremyliao.android.plugin.PrintLogPlugin -------------------------------------------------------------------------------- /android-gradle-study/app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | android-gradle-study 3 | 4 | -------------------------------------------------------------------------------- /android-gradle-study/plugin/src/main/resources/META-INF/gradle-plugins/ags-java-plugin.properties: -------------------------------------------------------------------------------- 1 | implementation-class=com.jeremyliao.plugin.AgsJavaPlugin -------------------------------------------------------------------------------- /android-gradle-study/testlibrary/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Test Library 3 | 4 | -------------------------------------------------------------------------------- /asm-demo/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JeremyLiao/android-gradle-study/HEAD/asm-demo/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /aspectj-demo/plugin/src/main/resources/META-INF/gradle-plugins/aspectj-plugin.properties: -------------------------------------------------------------------------------- 1 | implementation-class=com.jeremyliao.android.plugin.AspectJPlugin -------------------------------------------------------------------------------- /android-gradle-study/plugin/src/main/resources/META-INF/gradle-plugins/ags-groovy-plugin.properties: -------------------------------------------------------------------------------- 1 | implementation-class=com.jeremyliao.plugin.AgsGroovyPlugin -------------------------------------------------------------------------------- /android-gradle-study/plugin/src/main/resources/META-INF/gradle-plugins/dependency-plugin.properties: -------------------------------------------------------------------------------- 1 | implementation-class=com.jeremyliao.plugin.DependencyPlugin -------------------------------------------------------------------------------- /android-gradle-study/plugin1/src/main/resources/META-INF/gradle-plugins/ags-test-plugin.properties: -------------------------------------------------------------------------------- 1 | implementation-class=com.jeremyliao.plugin.AgsTestPlugin -------------------------------------------------------------------------------- /javassist-demo/plugin/src/main/resources/META-INF/gradle-plugins/javassist-plugin.properties: -------------------------------------------------------------------------------- 1 | implementation-class=com.jeremyliao.android.plugin.PrintLogPlugin -------------------------------------------------------------------------------- /android-gradle-study/plugin/src/main/resources/META-INF/gradle-plugins/classpath-plugin.properties: -------------------------------------------------------------------------------- 1 | implementation-class=com.jeremyliao.plugin.DynamicClasspathPlugin -------------------------------------------------------------------------------- /android-gradle-study/plugin/src/main/resources/META-INF/gradle-plugins/property-read-plugin.properties: -------------------------------------------------------------------------------- 1 | implementation-class=com.jeremyliao.plugin.PropertyReadPlugin -------------------------------------------------------------------------------- /aspectj-demo/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JeremyLiao/android-gradle-study/HEAD/aspectj-demo/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /javassist-demo/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JeremyLiao/android-gradle-study/HEAD/javassist-demo/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /aspectj-demo/base/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | -------------------------------------------------------------------------------- /asm-demo/app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JeremyLiao/android-gradle-study/HEAD/asm-demo/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /asm-demo/app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JeremyLiao/android-gradle-study/HEAD/asm-demo/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /aspectj-demo/apilib/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | -------------------------------------------------------------------------------- /android-gradle-study/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JeremyLiao/android-gradle-study/HEAD/android-gradle-study/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /asm-demo/app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JeremyLiao/android-gradle-study/HEAD/asm-demo/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /asm-demo/app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JeremyLiao/android-gradle-study/HEAD/asm-demo/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /asm-demo/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JeremyLiao/android-gradle-study/HEAD/asm-demo/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /aspectj-demo/app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JeremyLiao/android-gradle-study/HEAD/aspectj-demo/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /aspectj-demo/app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JeremyLiao/android-gradle-study/HEAD/aspectj-demo/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /aspectj-demo/app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JeremyLiao/android-gradle-study/HEAD/aspectj-demo/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /asm-demo/app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JeremyLiao/android-gradle-study/HEAD/asm-demo/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /asm-demo/app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JeremyLiao/android-gradle-study/HEAD/asm-demo/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /asm-demo/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JeremyLiao/android-gradle-study/HEAD/asm-demo/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /aspectj-demo/app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JeremyLiao/android-gradle-study/HEAD/aspectj-demo/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /aspectj-demo/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JeremyLiao/android-gradle-study/HEAD/aspectj-demo/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /javassist-demo/app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JeremyLiao/android-gradle-study/HEAD/javassist-demo/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /javassist-demo/app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JeremyLiao/android-gradle-study/HEAD/javassist-demo/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /javassist-demo/app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JeremyLiao/android-gradle-study/HEAD/javassist-demo/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /android-gradle-study/testlibrary/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | -------------------------------------------------------------------------------- /asm-demo/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JeremyLiao/android-gradle-study/HEAD/asm-demo/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /asm-demo/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JeremyLiao/android-gradle-study/HEAD/asm-demo/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /aspectj-demo/app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JeremyLiao/android-gradle-study/HEAD/aspectj-demo/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /aspectj-demo/app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JeremyLiao/android-gradle-study/HEAD/aspectj-demo/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /javassist-demo/app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JeremyLiao/android-gradle-study/HEAD/javassist-demo/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /javassist-demo/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JeremyLiao/android-gradle-study/HEAD/javassist-demo/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /android-gradle-study/app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JeremyLiao/android-gradle-study/HEAD/android-gradle-study/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /android-gradle-study/app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JeremyLiao/android-gradle-study/HEAD/android-gradle-study/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /aspectj-demo/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JeremyLiao/android-gradle-study/HEAD/aspectj-demo/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /aspectj-demo/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JeremyLiao/android-gradle-study/HEAD/aspectj-demo/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /javassist-demo/app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JeremyLiao/android-gradle-study/HEAD/javassist-demo/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /javassist-demo/app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JeremyLiao/android-gradle-study/HEAD/javassist-demo/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /android-gradle-study/app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JeremyLiao/android-gradle-study/HEAD/android-gradle-study/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /android-gradle-study/app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JeremyLiao/android-gradle-study/HEAD/android-gradle-study/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /android-gradle-study/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JeremyLiao/android-gradle-study/HEAD/android-gradle-study/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /aspectj-demo/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JeremyLiao/android-gradle-study/HEAD/aspectj-demo/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /javassist-demo/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JeremyLiao/android-gradle-study/HEAD/javassist-demo/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /javassist-demo/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JeremyLiao/android-gradle-study/HEAD/javassist-demo/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /javassist-demo/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JeremyLiao/android-gradle-study/HEAD/javassist-demo/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /android-gradle-study/app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JeremyLiao/android-gradle-study/HEAD/android-gradle-study/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /android-gradle-study/app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JeremyLiao/android-gradle-study/HEAD/android-gradle-study/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /android-gradle-study/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JeremyLiao/android-gradle-study/HEAD/android-gradle-study/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /android-gradle-study/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JeremyLiao/android-gradle-study/HEAD/android-gradle-study/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /android-gradle-study/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JeremyLiao/android-gradle-study/HEAD/android-gradle-study/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /asm-demo/base/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'java-library' 2 | 3 | dependencies { 4 | implementation fileTree(dir: 'libs', include: ['*.jar']) 5 | } 6 | 7 | sourceCompatibility = "7" 8 | targetCompatibility = "7" 9 | -------------------------------------------------------------------------------- /javassist-demo/base/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'java-library' 2 | 3 | dependencies { 4 | implementation fileTree(dir: 'libs', include: ['*.jar']) 5 | } 6 | 7 | sourceCompatibility = "7" 8 | targetCompatibility = "7" 9 | -------------------------------------------------------------------------------- /android-gradle-study/.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/caches/build_file_checksums.ser 5 | /.idea/libraries 6 | /.idea/modules.xml 7 | /.idea/workspace.xml 8 | .DS_Store 9 | /build 10 | /captures 11 | .externalNativeBuild 12 | -------------------------------------------------------------------------------- /asm-demo/app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #008577 4 | #00574B 5 | #D81B60 6 | 7 | -------------------------------------------------------------------------------- /android-gradle-study/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /aspectj-demo/app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #008577 4 | #00574B 5 | #D81B60 6 | 7 | -------------------------------------------------------------------------------- /javassist-demo/app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #008577 4 | #00574B 5 | #D81B60 6 | 7 | -------------------------------------------------------------------------------- /android-gradle-study/app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #008577 4 | #00574B 5 | #D81B60 6 | 7 | -------------------------------------------------------------------------------- /asm-demo/.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/caches 5 | /.idea/libraries 6 | /.idea/modules.xml 7 | /.idea/workspace.xml 8 | /.idea/navEditor.xml 9 | /.idea/assetWizardSettings.xml 10 | .DS_Store 11 | /build 12 | /captures 13 | .externalNativeBuild 14 | .cxx 15 | -------------------------------------------------------------------------------- /asm-demo/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Mon Sep 30 14:56:54 CST 2019 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip 7 | -------------------------------------------------------------------------------- /aspectj-demo/.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/caches 5 | /.idea/libraries 6 | /.idea/modules.xml 7 | /.idea/workspace.xml 8 | /.idea/navEditor.xml 9 | /.idea/assetWizardSettings.xml 10 | .DS_Store 11 | /build 12 | /captures 13 | .externalNativeBuild 14 | .cxx 15 | -------------------------------------------------------------------------------- /aspectj-demo/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Thu Sep 26 11:50:11 CST 2019 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip 7 | -------------------------------------------------------------------------------- /javassist-demo/.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/caches 5 | /.idea/libraries 6 | /.idea/modules.xml 7 | /.idea/workspace.xml 8 | /.idea/navEditor.xml 9 | /.idea/assetWizardSettings.xml 10 | .DS_Store 11 | /build 12 | /captures 13 | .externalNativeBuild 14 | .cxx 15 | -------------------------------------------------------------------------------- /javassist-demo/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Tue Oct 15 14:16:55 CST 2019 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip 7 | -------------------------------------------------------------------------------- /asm-demo/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /asm-demo/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /aspectj-demo/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /javassist-demo/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /aspectj-demo/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /android-gradle-study/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /javassist-demo/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /android-gradle-study/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /android-gradle-study/tools.gradle: -------------------------------------------------------------------------------- 1 | import java.text.SimpleDateFormat 2 | 3 | 4 | def getTimeStamp() { 5 | SimpleDateFormat sdf = new SimpleDateFormat("\"yyyy'.'MM'.'dd'-'HH':'mm':'ss\"") 6 | sdf.setTimeZone(TimeZone.getTimeZone("GMT+08:00")) 7 | return sdf.format(new Date()) 8 | } 9 | 10 | ext { 11 | getTimeStamp = this.&getTimeStamp 12 | } -------------------------------------------------------------------------------- /android-gradle-study/compiler/build.gradle: -------------------------------------------------------------------------------- 1 | import org.gradle.internal.jvm.Jvm 2 | 3 | apply plugin: 'java' 4 | 5 | dependencies { 6 | implementation fileTree(dir: 'libs', include: ['*.jar']) 7 | implementation 'com.google.auto.service:auto-service:1.0-rc4' 8 | compileOnly files(Jvm.current().getToolsJar()) 9 | } 10 | 11 | sourceCompatibility = "1.7" 12 | targetCompatibility = "1.7" 13 | -------------------------------------------------------------------------------- /aspectj-demo/base/src/main/java/com/jeremyliao/android/base/annotation/ExecutionTime.java: -------------------------------------------------------------------------------- 1 | package com.jeremyliao.android.base.annotation; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Retention(RetentionPolicy.CLASS) 9 | @Target({ElementType.METHOD}) 10 | public @interface ExecutionTime { 11 | } 12 | -------------------------------------------------------------------------------- /aspectj-demo/base/src/main/java/com/jeremyliao/android/base/annotation/MethodControl.java: -------------------------------------------------------------------------------- 1 | package com.jeremyliao.android.base.annotation; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Retention(RetentionPolicy.CLASS) 9 | @Target({ElementType.TYPE}) 10 | public @interface MethodControl { 11 | } 12 | -------------------------------------------------------------------------------- /android-gradle-study/app/src/main/java/com/jeremyliao/gradle/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.jeremyliao.gradle; 2 | 3 | import android.support.v7.app.AppCompatActivity; 4 | import android.os.Bundle; 5 | 6 | public class MainActivity extends AppCompatActivity { 7 | 8 | @Override 9 | protected void onCreate(Bundle savedInstanceState) { 10 | super.onCreate(savedInstanceState); 11 | setContentView(R.layout.activity_main); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /android-gradle-study/groovy_test.gradle: -------------------------------------------------------------------------------- 1 | task doRunEach << { 2 | runEach { 3 | println(it) 4 | } 5 | } 6 | 7 | def runEach(closure) { 8 | for (int i in 1..10) { 9 | closure(i) 10 | } 11 | } 12 | 13 | task doTestFirstLast { 14 | description 'doTestFirstLast task' 15 | doFirst { 16 | println("this action will run first!") 17 | } 18 | doLast { 19 | println("this action will run last!") 20 | } 21 | } -------------------------------------------------------------------------------- /asm-demo/app/src/main/java/com/jeremyliao/android/asm/TestTarget.java: -------------------------------------------------------------------------------- 1 | package com.jeremyliao.android.asm; 2 | 3 | /** 4 | * Created by liaohailiang on 2019-09-26. 5 | */ 6 | public class TestTarget { 7 | 8 | public int getIntValue() { 9 | return 10; 10 | } 11 | 12 | public boolean getBoolValue() { 13 | return true; 14 | } 15 | 16 | public int parseLong(long value) { 17 | return (int) value; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /asm-demo/app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /android-gradle-study/settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app', ':compiler', ':plugin', ':plugin1', ':testlibrary' 2 | 3 | println("setting.gradle: " + settings) 4 | gradle.beforeProject { 5 | project -> 6 | println("beforeProject: " + project) 7 | } 8 | gradle.afterProject { 9 | project -> 10 | println("afterProject: " + project) 11 | } 12 | 13 | ext { 14 | setting_ext_pro = 'hello' 15 | } 16 | 17 | println("setting_ext_pro: " + setting_ext_pro) 18 | -------------------------------------------------------------------------------- /asm-demo/base/src/main/java/com/jeremyliao/android/base/annotation/PrintLog.java: -------------------------------------------------------------------------------- 1 | package com.jeremyliao.android.base.annotation; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Retention(RetentionPolicy.CLASS) 9 | @Target({ElementType.METHOD, ElementType.TYPE, ElementType.CONSTRUCTOR}) 10 | public @interface PrintLog { 11 | } 12 | -------------------------------------------------------------------------------- /asm-demo/plugin/src/main/java/com/jeremyliao/android/base/annotation/PrintLog.java: -------------------------------------------------------------------------------- 1 | package com.jeremyliao.android.base.annotation; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Retention(RetentionPolicy.CLASS) 9 | @Target({ElementType.METHOD, ElementType.TYPE, ElementType.CONSTRUCTOR}) 10 | public @interface PrintLog { 11 | } 12 | -------------------------------------------------------------------------------- /aspectj-demo/app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /javassist-demo/app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /aspectj-demo/base/src/main/java/com/jeremyliao/android/base/annotation/PrintLog.java: -------------------------------------------------------------------------------- 1 | package com.jeremyliao.android.base.annotation; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Retention(RetentionPolicy.CLASS) 9 | @Target({ElementType.METHOD, ElementType.TYPE, ElementType.CONSTRUCTOR}) 10 | public @interface PrintLog { 11 | } 12 | -------------------------------------------------------------------------------- /javassist-demo/base/src/main/java/com/jeremyliao/android/base/annotation/PrintLog.java: -------------------------------------------------------------------------------- 1 | package com.jeremyliao.android.base.annotation; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Retention(RetentionPolicy.CLASS) 9 | @Target({ElementType.METHOD, ElementType.TYPE, ElementType.CONSTRUCTOR}) 10 | public @interface PrintLog { 11 | } 12 | -------------------------------------------------------------------------------- /javassist-demo/plugin/src/main/java/com/jeremyliao/android/base/annotation/PrintLog.java: -------------------------------------------------------------------------------- 1 | package com.jeremyliao.android.base.annotation; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Retention(RetentionPolicy.CLASS) 9 | @Target({ElementType.METHOD, ElementType.TYPE, ElementType.CONSTRUCTOR}) 10 | public @interface PrintLog { 11 | } 12 | -------------------------------------------------------------------------------- /android-gradle-study/app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /asm-demo/app/src/test/java/com/jeremyliao/android/asm/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.jeremyliao.android.asm; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /aspectj-demo/apilib/src/test/java/com/jeremyliao/android/apilib/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.jeremyliao.android.apilib; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /aspectj-demo/app/src/test/java/com/jeremyliao/android/aspectjdemo/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.jeremyliao.android.aspectjdemo; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /javassist-demo/app/src/test/java/com/jeremyliao/android/javassist/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.jeremyliao.android.javassist; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /android-gradle-study/testlibrary/src/test/java/com/jeremyliao/android/testlibrary/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.jeremyliao.android.testlibrary; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /aspectj-demo/apilib/src/main/java/com/jeremyliao/android/apilib/PrintLogDemo.java: -------------------------------------------------------------------------------- 1 | package com.jeremyliao.android.apilib; 2 | 3 | import com.jeremyliao.android.base.annotation.PrintLog; 4 | 5 | /** 6 | * Created by liaohailiang on 2019-09-26. 7 | */ 8 | @PrintLog 9 | public class PrintLogDemo { 10 | 11 | public int getIntValue() { 12 | return 10; 13 | } 14 | 15 | public boolean getBoolValue() { 16 | return true; 17 | } 18 | 19 | public int parseLong(long value) { 20 | return (int) value; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /aspectj-demo/apilib/src/main/java/com/jeremyliao/android/apilib/TestTarget.java: -------------------------------------------------------------------------------- 1 | package com.jeremyliao.android.apilib; 2 | 3 | import com.jeremyliao.android.base.annotation.MethodControl; 4 | 5 | /** 6 | * Created by liaohailiang on 2019-09-26. 7 | */ 8 | @MethodControl 9 | public class TestTarget { 10 | 11 | public int getIntValue() { 12 | return 10; 13 | } 14 | 15 | public boolean getBoolValue() { 16 | return true; 17 | } 18 | 19 | public int parseLong(long value) { 20 | return (int) value; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /asm-demo/plugin/src/main/groovy/com/jeremyliao/android/plugin/PrintLogPlugin.groovy: -------------------------------------------------------------------------------- 1 | package com.jeremyliao.android.plugin 2 | 3 | import com.android.build.gradle.AppExtension 4 | import com.jeremyliao.android.plugin.transform.PrintLogTransform 5 | import org.gradle.api.Plugin 6 | import org.gradle.api.Project 7 | 8 | /** 9 | * Created by liaohailiang on 2018/12/26. 10 | */ 11 | class PrintLogPlugin implements Plugin { 12 | 13 | @Override 14 | void apply(Project project) { 15 | def app = project.extensions.findByType(AppExtension.class) 16 | app.registerTransform(new PrintLogTransform()) 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /javassist-demo/plugin/src/main/groovy/com/jeremyliao/android/plugin/PrintLogPlugin.groovy: -------------------------------------------------------------------------------- 1 | package com.jeremyliao.android.plugin 2 | 3 | import com.android.build.gradle.AppExtension 4 | import com.jeremyliao.android.plugin.transform.PrintLogTransform 5 | import org.gradle.api.Plugin 6 | import org.gradle.api.Project 7 | 8 | /** 9 | * Created by liaohailiang on 2018/12/26. 10 | */ 11 | class PrintLogPlugin implements Plugin { 12 | 13 | @Override 14 | void apply(Project project) { 15 | def app = project.extensions.findByType(AppExtension.class) 16 | app.registerTransform(new PrintLogTransform(project)) 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /javassist-demo/app/src/main/java/com/jeremyliao/android/javassist/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.jeremyliao.android.javassist; 2 | 3 | import android.support.v7.app.AppCompatActivity; 4 | import android.os.Bundle; 5 | 6 | public class MainActivity extends AppCompatActivity { 7 | 8 | @Override 9 | protected void onCreate(Bundle savedInstanceState) { 10 | super.onCreate(savedInstanceState); 11 | setContentView(R.layout.activity_main); 12 | 13 | PrintLogDemo demo = new PrintLogDemo(); 14 | demo.getBoolValue(); 15 | demo.getIntValue(); 16 | demo.parseLong(100); 17 | demo.testLog(); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /asm-demo/app/src/main/java/com/jeremyliao/android/asm/PrintLogDemo.java: -------------------------------------------------------------------------------- 1 | package com.jeremyliao.android.asm; 2 | 3 | import android.util.Log; 4 | 5 | import com.jeremyliao.android.base.annotation.PrintLog; 6 | 7 | /** 8 | * Created by liaohailiang on 2019-09-26. 9 | */ 10 | @PrintLog 11 | public class PrintLogDemo { 12 | 13 | public int getIntValue() { 14 | return 10; 15 | } 16 | 17 | public boolean getBoolValue() { 18 | return true; 19 | } 20 | 21 | public int parseLong(long value) { 22 | return (int) value; 23 | } 24 | 25 | public void testLog() { 26 | Log.d("aa", "testLog"); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /javassist-demo/app/src/main/java/com/jeremyliao/android/javassist/PrintLogDemo.java: -------------------------------------------------------------------------------- 1 | package com.jeremyliao.android.javassist; 2 | 3 | import android.util.Log; 4 | 5 | import com.jeremyliao.android.base.annotation.PrintLog; 6 | 7 | /** 8 | * Created by liaohailiang on 2019-09-26. 9 | */ 10 | @PrintLog 11 | public class PrintLogDemo { 12 | 13 | public int getIntValue() { 14 | return 10; 15 | } 16 | 17 | public boolean getBoolValue() { 18 | return true; 19 | } 20 | 21 | public int parseLong(long value) { 22 | return (int) value; 23 | } 24 | 25 | public void testLog() { 26 | Log.d("aa", "testLog"); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /aspectj-demo/base/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | apply plugin: 'aspectj-plugin' 3 | 4 | android { 5 | compileSdkVersion 28 6 | 7 | defaultConfig { 8 | minSdkVersion 15 9 | targetSdkVersion 28 10 | versionCode 1 11 | versionName "1.0" 12 | } 13 | 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | 21 | } 22 | 23 | dependencies { 24 | implementation fileTree(dir: 'libs', include: ['*.jar']) 25 | implementation 'com.android.support:appcompat-v7:28.0.0' 26 | } 27 | -------------------------------------------------------------------------------- /android-gradle-study/compiler/src/main/java/com/jeremyliao/compiler/AgsProcessor.java: -------------------------------------------------------------------------------- 1 | package com.jeremyliao.compiler; 2 | 3 | import com.google.auto.service.AutoService; 4 | 5 | import java.util.Set; 6 | 7 | import javax.annotation.processing.AbstractProcessor; 8 | import javax.annotation.processing.Processor; 9 | import javax.annotation.processing.RoundEnvironment; 10 | import javax.lang.model.element.TypeElement; 11 | 12 | /** 13 | * Created by liaohailiang on 2018/12/26. 14 | */ 15 | @AutoService(Processor.class) 16 | public class AgsProcessor extends AbstractProcessor { 17 | 18 | @Override 19 | public boolean process(Set set, RoundEnvironment roundEnvironment) { 20 | return false; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /asm-demo/build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | repositories { 5 | maven { 6 | url uri('./repo') 7 | } 8 | google() 9 | jcenter() 10 | } 11 | dependencies { 12 | classpath 'com.android.tools.build:gradle:3.2.1' 13 | classpath "com.jeremyliao.gradle:plugin:0.0.1" 14 | // NOTE: Do not place your application dependencies here; they belong 15 | // in the individual module build.gradle files 16 | } 17 | } 18 | 19 | allprojects { 20 | repositories { 21 | google() 22 | jcenter() 23 | 24 | } 25 | } 26 | 27 | task clean(type: Delete) { 28 | delete rootProject.buildDir 29 | } 30 | -------------------------------------------------------------------------------- /asm-demo/app/src/main/java/com/jeremyliao/android/asm/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.jeremyliao.android.asm; 2 | 3 | import android.support.v7.app.AppCompatActivity; 4 | import android.os.Bundle; 5 | 6 | public class MainActivity extends AppCompatActivity { 7 | 8 | @Override 9 | protected void onCreate(Bundle savedInstanceState) { 10 | super.onCreate(savedInstanceState); 11 | setContentView(R.layout.activity_main); 12 | 13 | TestTarget target = new TestTarget(); 14 | target.getBoolValue(); 15 | target.getIntValue(); 16 | target.parseLong(100); 17 | 18 | PrintLogDemo demo = new PrintLogDemo(); 19 | demo.getBoolValue(); 20 | demo.getIntValue(); 21 | demo.parseLong(100); 22 | demo.testLog(); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /asm-demo/gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | # IDE (e.g. Android Studio) users: 3 | # Gradle settings configured through the IDE *will override* 4 | # any settings specified in this file. 5 | # For more details on how to configure your build environment visit 6 | # http://www.gradle.org/docs/current/userguide/build_environment.html 7 | # Specifies the JVM arguments used for the daemon process. 8 | # The setting is particularly useful for tweaking memory settings. 9 | org.gradle.jvmargs=-Xmx1536m 10 | # When configured, Gradle will run in incubating parallel mode. 11 | # This option should only be used with decoupled projects. More details, visit 12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 13 | # org.gradle.parallel=true 14 | 15 | 16 | -------------------------------------------------------------------------------- /aspectj-demo/build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | repositories { 5 | maven { 6 | url uri('./repo') 7 | } 8 | google() 9 | jcenter() 10 | 11 | } 12 | dependencies { 13 | classpath 'com.android.tools.build:gradle:3.2.1' 14 | classpath "com.jeremyliao.gradle:plugin:0.0.1" 15 | // NOTE: Do not place your application dependencies here; they belong 16 | // in the individual module build.gradle files 17 | } 18 | } 19 | 20 | allprojects { 21 | repositories { 22 | google() 23 | jcenter() 24 | 25 | } 26 | } 27 | 28 | task clean(type: Delete) { 29 | delete rootProject.buildDir 30 | } 31 | -------------------------------------------------------------------------------- /aspectj-demo/gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | # IDE (e.g. Android Studio) users: 3 | # Gradle settings configured through the IDE *will override* 4 | # any settings specified in this file. 5 | # For more details on how to configure your build environment visit 6 | # http://www.gradle.org/docs/current/userguide/build_environment.html 7 | # Specifies the JVM arguments used for the daemon process. 8 | # The setting is particularly useful for tweaking memory settings. 9 | org.gradle.jvmargs=-Xmx1536m 10 | # When configured, Gradle will run in incubating parallel mode. 11 | # This option should only be used with decoupled projects. More details, visit 12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 13 | # org.gradle.parallel=true 14 | 15 | 16 | -------------------------------------------------------------------------------- /javassist-demo/build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | repositories { 5 | maven { 6 | url uri('./repo') 7 | } 8 | google() 9 | jcenter() 10 | 11 | } 12 | dependencies { 13 | classpath 'com.android.tools.build:gradle:3.2.1' 14 | classpath "com.jeremyliao.gradle:plugin:0.0.1" 15 | // NOTE: Do not place your application dependencies here; they belong 16 | // in the individual module build.gradle files 17 | } 18 | } 19 | 20 | allprojects { 21 | repositories { 22 | google() 23 | jcenter() 24 | 25 | } 26 | } 27 | 28 | task clean(type: Delete) { 29 | delete rootProject.buildDir 30 | } 31 | -------------------------------------------------------------------------------- /javassist-demo/gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | # IDE (e.g. Android Studio) users: 3 | # Gradle settings configured through the IDE *will override* 4 | # any settings specified in this file. 5 | # For more details on how to configure your build environment visit 6 | # http://www.gradle.org/docs/current/userguide/build_environment.html 7 | # Specifies the JVM arguments used for the daemon process. 8 | # The setting is particularly useful for tweaking memory settings. 9 | org.gradle.jvmargs=-Xmx1536m 10 | # When configured, Gradle will run in incubating parallel mode. 11 | # This option should only be used with decoupled projects. More details, visit 12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 13 | # org.gradle.parallel=true 14 | 15 | 16 | -------------------------------------------------------------------------------- /asm-demo/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /asm-demo/plugin/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'groovy' 2 | apply plugin: 'maven' 3 | 4 | sourceSets { 5 | main { 6 | groovy { 7 | srcDir 'src/main/groovy' 8 | } 9 | 10 | java { 11 | srcDir 'src/main/java' 12 | } 13 | } 14 | } 15 | 16 | dependencies { 17 | implementation gradleApi() 18 | implementation localGroovy() 19 | implementation 'com.android.tools.build:gradle:3.1.1' 20 | implementation 'com.android.tools.build:transform-api:1.5.0' 21 | } 22 | 23 | sourceCompatibility = "1.7" 24 | targetCompatibility = "1.7" 25 | 26 | //打包到本地或者远程Maven库 27 | group = 'com.jeremyliao.gradle' 28 | version = '0.0.1' 29 | 30 | uploadArchives { 31 | repositories { 32 | mavenDeployer { 33 | repository(url: uri('../repo')) 34 | } 35 | } 36 | } -------------------------------------------------------------------------------- /android-gradle-study/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /javassist-demo/plugin/src/main/java/com/jeremyliao/android/plugin/handler/JavassistHandler.java: -------------------------------------------------------------------------------- 1 | package com.jeremyliao.android.plugin.handler; 2 | 3 | import com.android.build.api.transform.DirectoryInput; 4 | 5 | import java.io.File; 6 | 7 | import javassist.ClassPool; 8 | import javassist.NotFoundException; 9 | 10 | /** 11 | * Created by liaohailiang on 2019-10-15. 12 | */ 13 | public class JavassistHandler { 14 | 15 | //初始化类池 16 | private final static ClassPool pool = ClassPool.getDefault(); 17 | 18 | public static void handle(DirectoryInput directoryInput) throws NotFoundException { 19 | File file = directoryInput.getFile(); 20 | String absolutePath = file.getAbsolutePath(); 21 | pool.appendClassPath(absolutePath); 22 | 23 | if (file.isDirectory()){ 24 | 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /aspectj-demo/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /javassist-demo/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /asm-demo/app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /aspectj-demo/app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /aspectj-demo/base/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /aspectj-demo/apilib/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /javassist-demo/app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /android-gradle-study/app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /android-gradle-study/testlibrary/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /asm-demo/app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 17 | 18 | -------------------------------------------------------------------------------- /aspectj-demo/app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 17 | 18 | -------------------------------------------------------------------------------- /aspectj-demo/plugin/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'groovy' 2 | apply plugin: 'maven' 3 | 4 | sourceSets { 5 | main { 6 | groovy { 7 | srcDir 'src/main/groovy' 8 | } 9 | 10 | java { 11 | srcDir 'src/main/java' 12 | } 13 | } 14 | } 15 | 16 | dependencies { 17 | implementation gradleApi() 18 | implementation localGroovy() 19 | implementation 'com.android.tools.build:gradle:3.1.1' 20 | implementation 'org.aspectj:aspectjtools:1.9.1' 21 | implementation 'org.aspectj:aspectjrt:1.9.1' 22 | 23 | } 24 | 25 | sourceCompatibility = "1.7" 26 | targetCompatibility = "1.7" 27 | 28 | //打包到本地或者远程Maven库 29 | group = 'com.jeremyliao.gradle' 30 | version = '0.0.1' 31 | 32 | uploadArchives { 33 | repositories { 34 | mavenDeployer { 35 | repository(url: uri('../repo')) 36 | } 37 | } 38 | } -------------------------------------------------------------------------------- /javassist-demo/app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 17 | 18 | -------------------------------------------------------------------------------- /android-gradle-study/app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 17 | 18 | -------------------------------------------------------------------------------- /android-gradle-study/testlibrary/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | 3 | android { 4 | compileSdkVersion 28 5 | 6 | 7 | defaultConfig { 8 | minSdkVersion 15 9 | targetSdkVersion 28 10 | versionCode 1 11 | versionName "1.0" 12 | 13 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 14 | consumerProguardFiles 'consumer-rules.pro' 15 | } 16 | 17 | buildTypes { 18 | release { 19 | minifyEnabled false 20 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 21 | } 22 | } 23 | 24 | } 25 | 26 | dependencies { 27 | implementation fileTree(dir: 'libs', include: ['*.jar']) 28 | implementation 'com.android.support:appcompat-v7:28.0.0' 29 | implementation 'android.arch.lifecycle:livedata:1.1.1' 30 | } 31 | -------------------------------------------------------------------------------- /javassist-demo/plugin/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'groovy' 2 | apply plugin: 'maven' 3 | 4 | sourceSets { 5 | main { 6 | groovy { 7 | srcDir 'src/main/groovy' 8 | } 9 | 10 | java { 11 | srcDir 'src/main/java' 12 | } 13 | } 14 | } 15 | 16 | dependencies { 17 | implementation gradleApi() 18 | implementation localGroovy() 19 | implementation 'com.android.tools.build:gradle:3.1.1' 20 | implementation 'com.android.tools.build:transform-api:1.5.0' 21 | implementation 'org.javassist:javassist:3.24.1-GA' 22 | } 23 | 24 | sourceCompatibility = "1.7" 25 | targetCompatibility = "1.7" 26 | 27 | //打包到本地或者远程Maven库 28 | group = 'com.jeremyliao.gradle' 29 | version = '0.0.1' 30 | 31 | uploadArchives { 32 | repositories { 33 | mavenDeployer { 34 | repository(url: uri('../repo')) 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /android-gradle-study/gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | # IDE (e.g. Android Studio) users: 3 | # Gradle settings configured through the IDE *will override* 4 | # any settings specified in this file. 5 | # For more details on how to configure your build environment visit 6 | # http://www.gradle.org/docs/current/userguide/build_environment.html 7 | # Specifies the JVM arguments used for the daemon process. 8 | # The setting is particularly useful for tweaking memory settings. 9 | org.gradle.jvmargs=-Xmx1536m 10 | # When configured, Gradle will run in incubating parallel mode. 11 | # This option should only be used with decoupled projects. More details, visit 12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 13 | # org.gradle.parallel=true 14 | systemProp.foo=bar 15 | BUTTERKNIFE_PLUGIN_VERSION=9.0.0 16 | PLUGIN1_VERSION=0.0.1 17 | systemProp.demoPro=helloworld 18 | a.b.c=helloworld 19 | -------------------------------------------------------------------------------- /asm-demo/app/src/androidTest/java/com/jeremyliao/android/asm/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.jeremyliao.android.asm; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumented test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); 23 | 24 | assertEquals("com.jeremyliao.android.asm", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /aspectj-demo/apilib/src/androidTest/java/com/jeremyliao/android/apilib/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.jeremyliao.android.apilib; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumented test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); 23 | 24 | assertEquals("com.jeremyliao.android.apilib.test", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /javassist-demo/app/src/androidTest/java/com/jeremyliao/android/javassist/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.jeremyliao.android.javassist; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumented test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); 23 | 24 | assertEquals("com.jeremyliao.android.javassist", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /aspectj-demo/app/src/androidTest/java/com/jeremyliao/android/aspectjdemo/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.jeremyliao.android.aspectjdemo; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumented test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); 23 | 24 | assertEquals("com.jeremyliao.android.aspectjdemo", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /android-gradle-study/plugin1/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'groovy' 2 | apply plugin: 'java' 3 | apply plugin: 'maven' 4 | 5 | repositories { 6 | mavenLocal() 7 | jcenter() 8 | } 9 | 10 | sourceSets { 11 | main { 12 | groovy { 13 | srcDir 'src/main/groovy' 14 | } 15 | 16 | java { 17 | srcDir 'src/main/java' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | implementation fileTree(dir: 'libs', include: ['*.jar']) 24 | compile gradleApi() 25 | compile localGroovy() 26 | compile 'com.android.tools.build:gradle:3.1.1' 27 | compile 'com.android.tools.build:transform-api:1.5.0' 28 | } 29 | 30 | sourceCompatibility = "1.7" 31 | targetCompatibility = "1.7" 32 | 33 | //打包到本地或者远程Maven库 34 | group = 'com.jeremyliao.gradle' 35 | version = '0.0.1' 36 | 37 | uploadArchives { 38 | repositories { 39 | mavenDeployer { 40 | repository(url: uri('../repo')) 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /android-gradle-study/plugin/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'groovy' 2 | apply plugin: 'java' 3 | apply plugin: 'maven' 4 | 5 | repositories { 6 | mavenLocal() 7 | jcenter() 8 | } 9 | 10 | sourceSets { 11 | main { 12 | groovy { 13 | srcDir 'src/main/groovy' 14 | } 15 | 16 | java { 17 | srcDir 'src/main/java' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | implementation fileTree(dir: 'libs', include: ['*.jar']) 24 | implementation gradleApi() 25 | implementation localGroovy() 26 | implementation 'com.android.tools.build:gradle:3.1.1' 27 | implementation 'com.android.tools.build:transform-api:1.5.0' 28 | } 29 | 30 | sourceCompatibility = "1.7" 31 | targetCompatibility = "1.7" 32 | 33 | //打包到本地或者远程Maven库 34 | group = 'com.jeremyliao.gradle' 35 | version = '0.0.1' 36 | 37 | uploadArchives { 38 | repositories { 39 | mavenDeployer { 40 | repository(url: uri('../repo')) 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /aspectj-demo/apilib/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | apply plugin: 'aspectj-plugin' 3 | 4 | android { 5 | compileSdkVersion 28 6 | 7 | 8 | defaultConfig { 9 | minSdkVersion 15 10 | targetSdkVersion 28 11 | versionCode 1 12 | versionName "1.0" 13 | 14 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 15 | consumerProguardFiles 'consumer-rules.pro' 16 | } 17 | 18 | buildTypes { 19 | release { 20 | minifyEnabled false 21 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 22 | } 23 | } 24 | 25 | } 26 | 27 | dependencies { 28 | implementation fileTree(dir: 'libs', include: ['*.jar']) 29 | 30 | implementation 'com.android.support:appcompat-v7:28.0.0' 31 | testImplementation 'junit:junit:4.12' 32 | androidTestImplementation 'com.android.support.test:runner:1.0.2' 33 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' 34 | implementation project(path: ':base') 35 | } 36 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Jeremy Liao 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /asm-demo/app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | apply plugin: 'asm-plugin' 3 | 4 | android { 5 | compileSdkVersion 28 6 | defaultConfig { 7 | applicationId "com.jeremyliao.android.asm" 8 | minSdkVersion 15 9 | targetSdkVersion 28 10 | versionCode 1 11 | versionName "1.0" 12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | implementation fileTree(dir: 'libs', include: ['*.jar']) 24 | implementation 'com.android.support:appcompat-v7:28.0.0' 25 | implementation 'com.android.support.constraint:constraint-layout:1.1.3' 26 | testImplementation 'junit:junit:4.12' 27 | androidTestImplementation 'com.android.support.test:runner:1.0.2' 28 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' 29 | implementation project(path: ':base') 30 | } 31 | -------------------------------------------------------------------------------- /aspectj-demo/base/src/main/java/com/jeremyliao/android/base/aspect/ExecutionTimeAspect.java: -------------------------------------------------------------------------------- 1 | package com.jeremyliao.android.base.aspect; 2 | 3 | import android.util.Log; 4 | 5 | import org.aspectj.lang.ProceedingJoinPoint; 6 | import org.aspectj.lang.annotation.Around; 7 | import org.aspectj.lang.annotation.Aspect; 8 | import org.aspectj.lang.annotation.Pointcut; 9 | 10 | /** 11 | * Created by liaohailiang on 2019-09-26. 12 | */ 13 | @Aspect 14 | public class ExecutionTimeAspect { 15 | 16 | private static String TAG = "[ExecutionTime]"; 17 | 18 | @Pointcut("execution(@com.jeremyliao.android.base.annotation.ExecutionTime * *(..))") 19 | public void executeMethod() { 20 | } 21 | 22 | @Around("executeMethod()") 23 | public Object printExcutionTime(ProceedingJoinPoint joinPoint) throws Throwable { 24 | long startTimeMillis = System.currentTimeMillis(); 25 | Object result = joinPoint.proceed(); 26 | long executionTime = System.currentTimeMillis() - startTimeMillis; 27 | Log.d(TAG, joinPoint.getSignature() + " execution cost time: " + executionTime + "ms"); 28 | return result; 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /javassist-demo/app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | apply plugin: 'javassist-plugin' 3 | 4 | android { 5 | compileSdkVersion 28 6 | defaultConfig { 7 | applicationId "com.jeremyliao.android.javassist" 8 | minSdkVersion 15 9 | targetSdkVersion 28 10 | versionCode 1 11 | versionName "1.0" 12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | implementation fileTree(dir: 'libs', include: ['*.jar']) 24 | implementation 'com.android.support:appcompat-v7:28.0.0' 25 | implementation 'com.android.support.constraint:constraint-layout:1.1.3' 26 | testImplementation 'junit:junit:4.12' 27 | androidTestImplementation 'com.android.support.test:runner:1.0.2' 28 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' 29 | implementation project(path: ':base') 30 | } 31 | -------------------------------------------------------------------------------- /aspectj-demo/app/src/main/java/com/jeremyliao/android/aspectjdemo/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.jeremyliao.android.aspectjdemo; 2 | 3 | import android.support.v7.app.AppCompatActivity; 4 | import android.os.Bundle; 5 | 6 | import com.jeremyliao.android.apilib.PrintLogDemo; 7 | import com.jeremyliao.android.apilib.TestTarget; 8 | import com.jeremyliao.android.base.annotation.ExecutionTime; 9 | 10 | public class MainActivity extends AppCompatActivity { 11 | 12 | @Override 13 | protected void onCreate(Bundle savedInstanceState) { 14 | super.onCreate(savedInstanceState); 15 | setContentView(R.layout.activity_main); 16 | test(); 17 | TestTarget target = new TestTarget(); 18 | target.getBoolValue(); 19 | target.getIntValue(); 20 | target.parseLong(100); 21 | PrintLogDemo demo = new PrintLogDemo(); 22 | demo.getBoolValue(); 23 | demo.getIntValue(); 24 | demo.parseLong(100); 25 | } 26 | 27 | @ExecutionTime 28 | private void test() { 29 | try { 30 | Thread.sleep(500); 31 | } catch (InterruptedException e) { 32 | e.printStackTrace(); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /aspectj-demo/app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | apply plugin: 'aspectj-plugin' 3 | 4 | android { 5 | compileSdkVersion 28 6 | defaultConfig { 7 | applicationId "com.jeremyliao.android.aspectjdemo" 8 | minSdkVersion 15 9 | targetSdkVersion 28 10 | versionCode 1 11 | versionName "1.0" 12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | implementation fileTree(dir: 'libs', include: ['*.jar']) 24 | implementation 'com.android.support:appcompat-v7:28.0.0' 25 | implementation 'com.android.support.constraint:constraint-layout:1.1.3' 26 | testImplementation 'junit:junit:4.12' 27 | androidTestImplementation 'com.android.support.test:runner:1.0.2' 28 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' 29 | implementation project(path: ':base') 30 | implementation project(path: ':apilib') 31 | } 32 | -------------------------------------------------------------------------------- /aspectj-demo/base/src/main/java/com/jeremyliao/android/base/aspect/MethodControlAspect.java: -------------------------------------------------------------------------------- 1 | package com.jeremyliao.android.base.aspect; 2 | 3 | import android.util.Log; 4 | 5 | import org.aspectj.lang.ProceedingJoinPoint; 6 | import org.aspectj.lang.annotation.Around; 7 | import org.aspectj.lang.annotation.Aspect; 8 | import org.aspectj.lang.annotation.Pointcut; 9 | 10 | /** 11 | * Created by liaohailiang on 2019-09-26. 12 | */ 13 | @Aspect 14 | public class MethodControlAspect { 15 | 16 | private static String TAG = "[ExecutionTime]"; 17 | 18 | @Pointcut("within(@com.jeremyliao.android.base.annotation.MethodControl *)") 19 | public void codeInTarget() { 20 | } 21 | 22 | @Pointcut("execution(public * *(..))") 23 | public void publicMethod() { 24 | } 25 | 26 | @Around("codeInTarget() && publicMethod()") 27 | public Object printExcutionTime(ProceedingJoinPoint joinPoint) throws Throwable { 28 | long startTimeMillis = System.currentTimeMillis(); 29 | Object result = joinPoint.proceed(); 30 | long executionTime = System.currentTimeMillis() - startTimeMillis; 31 | Log.d(TAG, joinPoint.getSignature() + " execution cost time: " + executionTime + "ms"); 32 | return result; 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /android-gradle-study/plugin/src/main/java/com/jeremyliao/plugin/extension/DemoExtension.java: -------------------------------------------------------------------------------- 1 | package com.jeremyliao.plugin.extension; 2 | 3 | import java.util.List; 4 | 5 | /** 6 | * Created by liaohailiang on 2019/1/25. 7 | */ 8 | public class DemoExtension { 9 | 10 | private boolean enable; 11 | private String message; 12 | private List strings; 13 | 14 | public boolean isEnable() { 15 | return enable; 16 | } 17 | 18 | public void setEnable(boolean enable) { 19 | this.enable = enable; 20 | } 21 | 22 | public String getMessage() { 23 | return message; 24 | } 25 | 26 | public void setMessage(String message) { 27 | this.message = message; 28 | } 29 | 30 | public List getStrings() { 31 | return strings; 32 | } 33 | 34 | public void setStrings(List strings) { 35 | this.strings = strings; 36 | } 37 | 38 | @Override 39 | public String toString() { 40 | StringBuilder sb = new StringBuilder(); 41 | sb.append("enable=").append(enable).append(";"); 42 | sb.append("message=").append(message).append(";"); 43 | sb.append("strings=").append(strings).append(";"); 44 | return sb.toString(); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /android-gradle-study/plugin1/src/main/groovy/com/jeremyliao/plugin/AgsTestPlugin.groovy: -------------------------------------------------------------------------------- 1 | package com.jeremyliao.plugin 2 | 3 | import com.jeremyliao.plugin.utils.GradleUtils 4 | import org.gradle.api.Plugin 5 | import org.gradle.api.Project 6 | 7 | /** 8 | * Created by liaohailiang on 2018/12/26. 9 | */ 10 | class AgsTestPlugin implements Plugin { 11 | 12 | final String TAG = "[AgsTestPlugin]" 13 | 14 | @Override 15 | void apply(Project project) { 16 | System.out.println(TAG + project) 17 | project.android.applicationVariants.all { variant -> 18 | System.out.println(TAG + "variant: " + variant) 19 | def packageTask = project.tasks.findByName("package${variant.name.capitalize()}") 20 | System.out.println(TAG + "packageTask: " + packageTask) 21 | System.out.println(TAG + "gradlePluginVersion: " + GradleUtils.gradlePluginVersion) 22 | System.out.println(TAG + "gradlePlugin300orAbove: " + GradleUtils.gradlePlugin300orAbove) 23 | packageTask.doFirst { 24 | System.out.println(TAG + "doFirst --> gradlePluginVersion: " + GradleUtils.gradlePluginVersion) 25 | System.out.println(TAG + "doFirst --> gradlePlugin300orAbove: " + GradleUtils.gradlePlugin300orAbove) 26 | } 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /android-gradle-study/plugin1/src/main/groovy/com/jeremyliao/plugin/utils/GradleUtils.groovy: -------------------------------------------------------------------------------- 1 | package com.jeremyliao.plugin.utils 2 | 3 | import org.gradle.api.Plugin 4 | import org.gradle.api.Project 5 | 6 | /** 7 | * Created by liaohailiang on 2018/12/26. 8 | */ 9 | class GradleUtils { 10 | 11 | static String getGradlePluginVersion() { 12 | String version = null 13 | try { 14 | def clazz = Class.forName("com.android.builder.Version") 15 | def field = clazz.getDeclaredField("ANDROID_GRADLE_PLUGIN_VERSION") 16 | field.setAccessible(true) 17 | version = field.get(null) 18 | } catch (Exception ignore) { 19 | } 20 | if (version == null) { 21 | try { 22 | def clazz = Class.forName("com.android.builder.model.Version") 23 | def field = clazz.getDeclaredField("ANDROID_GRADLE_PLUGIN_VERSION") 24 | field.setAccessible(true) 25 | version = field.get(null) 26 | } catch (Exception ignore) { 27 | } 28 | } 29 | return version 30 | } 31 | 32 | static boolean isGradlePlugin300orAbove() { 33 | try { 34 | String gradlePluginVersion = getGradlePluginVersion() 35 | return gradlePluginVersion.compareTo("3.0.0") >= 0 36 | } catch (Throwable throwable) { 37 | 38 | } 39 | return false 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /android-gradle-study/plugin/src/main/java/com/jeremyliao/plugin/AgsJavaPlugin.java: -------------------------------------------------------------------------------- 1 | package com.jeremyliao.plugin; 2 | 3 | import com.android.build.gradle.BaseExtension; 4 | import com.jeremyliao.plugin.extension.DemoExtension; 5 | 6 | import org.gradle.api.Action; 7 | import org.gradle.api.Plugin; 8 | import org.gradle.api.Project; 9 | 10 | /** 11 | * Created by liaohailiang on 2018/12/26. 12 | */ 13 | public class AgsJavaPlugin implements Plugin { 14 | 15 | private static final String TAG = "[AgsJavaPlugin]"; 16 | 17 | @Override 18 | public void apply(Project project) { 19 | System.out.println(TAG + project); 20 | BaseExtension baseExtension = project.getExtensions().findByType(BaseExtension.class); 21 | System.out.println(TAG + baseExtension); 22 | 23 | final DemoExtension extension = project.getExtensions().create("demoConfig", DemoExtension.class); 24 | System.out.println(TAG + "extension: " + extension); 25 | 26 | String testProperty = (String) project.property("testProperty"); 27 | System.out.println(TAG + "testProperty: " + testProperty); 28 | 29 | Object ext_pro = project.property("ext_pro"); 30 | System.out.println(TAG + "ext_pro: " + ext_pro); 31 | 32 | project.afterEvaluate(new Action() { 33 | @Override 34 | public void execute(Project project) { 35 | System.out.println(TAG + "extension afterEvaluate: " + extension); 36 | } 37 | }); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /android-gradle-study/plugin/src/main/groovy/com/jeremyliao/plugin/PropertyReadPlugin.groovy: -------------------------------------------------------------------------------- 1 | package com.jeremyliao.plugin 2 | 3 | 4 | import org.gradle.api.Plugin 5 | import org.gradle.api.Project 6 | 7 | /** 8 | * Created by liaohailiang on 2018/12/26. 9 | * demo for read property 10 | */ 11 | class PropertyReadPlugin implements Plugin { 12 | 13 | final String TAG = "[PropertyReadPlugin]" 14 | 15 | @Override 16 | void apply(Project project) { 17 | readSystemProperty() 18 | readProperty(project) 19 | readFile(project) 20 | } 21 | 22 | /** 23 | * 读取SystemProperty的方法 24 | * 定义在gradle.property中 25 | * 如:systemProp.demoPro=helloworld 26 | */ 27 | private void readSystemProperty() { 28 | System.out.println(TAG + " system property demoPro: " + System.getProperty("demoPro")) 29 | } 30 | 31 | /** 32 | * 读取Property的方法 33 | * 定义在gradle.property中 34 | * 如:a.b.c=helloworld 35 | */ 36 | private void readProperty(Project project) { 37 | def props = new Properties() 38 | props.load(project.rootProject.file('gradle.properties').newDataInputStream()) 39 | def property = props.getProperty("a.b.c") 40 | System.out.println(TAG + " property a.b.c: " + property) 41 | } 42 | 43 | /** 44 | * 读取file的方法 45 | * 46 | */ 47 | private void readFile(Project project) { 48 | File file = project.rootProject.file('white_list.prop') 49 | def lines = file.readLines() 50 | System.out.println(TAG + " readLines: " + lines) 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Built application files 2 | *.apk 3 | *.ap_ 4 | 5 | # Files for the ART/Dalvik VM 6 | *.dex 7 | 8 | # Java class files 9 | *.class 10 | 11 | # Generated files 12 | bin/ 13 | gen/ 14 | out/ 15 | 16 | # Gradle files 17 | .gradle/ 18 | build/ 19 | 20 | # Local configuration file (sdk path, etc) 21 | local.properties 22 | 23 | # Proguard folder generated by Eclipse 24 | proguard/ 25 | 26 | # Log Files 27 | *.log 28 | 29 | # Android Studio Navigation editor temp files 30 | .navigation/ 31 | 32 | # Android Studio captures folder 33 | captures/ 34 | 35 | # IntelliJ 36 | *.iml 37 | .idea/workspace.xml 38 | .idea/tasks.xml 39 | .idea/gradle.xml 40 | .idea/assetWizardSettings.xml 41 | .idea/dictionaries 42 | .idea/libraries 43 | .idea/caches 44 | 45 | # Keystore files 46 | # Uncomment the following line if you do not want to check your keystore files in. 47 | #*.jks 48 | 49 | # External native build folder generated in Android Studio 2.2 and later 50 | .externalNativeBuild 51 | 52 | # Google Services (e.g. APIs or Firebase) 53 | google-services.json 54 | 55 | # Freeline 56 | freeline.py 57 | freeline/ 58 | freeline_project_description.json 59 | 60 | # fastlane 61 | fastlane/report.xml 62 | fastlane/Preview.html 63 | fastlane/screenshots 64 | fastlane/test_output 65 | fastlane/readme.md 66 | 67 | release 68 | target 69 | build 70 | .settings 71 | .project 72 | .classpath 73 | .idea 74 | .DS_Store 75 | bin 76 | gen 77 | proguard 78 | .pmd 79 | *~ 80 | *.iml 81 | tmp 82 | gen-external-apklibs 83 | out 84 | tmp 85 | coverage 86 | build/ 87 | .gradle/ 88 | local.properties 89 | .gradletasknamecache 90 | src/main/provided_libs 91 | src/main/assets/*.dex 92 | src/main/assets/mtdata*.json 93 | reports/ 94 | aartojar/ 95 | keystore 96 | captures 97 | repo/ 98 | -------------------------------------------------------------------------------- /asm-demo/plugin/src/main/java/com/jeremyliao/android/plugin/OnCreateMethodVisitor.java: -------------------------------------------------------------------------------- 1 | package com.jeremyliao.android.plugin; 2 | 3 | import org.objectweb.asm.MethodVisitor; 4 | import org.objectweb.asm.Opcodes; 5 | 6 | /** 7 | * Created by liaohailiang on 2019-09-30. 8 | */ 9 | public class OnCreateMethodVisitor extends MethodVisitor { 10 | 11 | public OnCreateMethodVisitor(MethodVisitor mv) { 12 | super(Opcodes.ASM4, mv); 13 | } 14 | 15 | @Override 16 | public void visitCode() { 17 | super.visitCode(); 18 | //方法执行前插入 19 | mv.visitLdcInsn("TAG"); 20 | mv.visitTypeInsn(Opcodes.NEW, "java/lang/StringBuilder"); 21 | mv.visitInsn(Opcodes.DUP); 22 | mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/StringBuilder", "", "()V", false); 23 | mv.visitLdcInsn("-------> onCreate : "); 24 | mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(Ljava/lang/String;)Ljava/lang/StringBuilder;", false); 25 | mv.visitVarInsn(Opcodes.ALOAD, 0); 26 | mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Object", "getClass", "()Ljava/lang/Class;", false); 27 | mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Class", "getSimpleName", "()Ljava/lang/String;", false); 28 | mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(Ljava/lang/String;)Ljava/lang/StringBuilder;", false); 29 | mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/StringBuilder", "toString", "()Ljava/lang/String;", false); 30 | mv.visitMethodInsn(Opcodes.INVOKESTATIC, "android/util/Log", "i", "(Ljava/lang/String;Ljava/lang/String;)I", false); 31 | mv.visitInsn(Opcodes.POP); 32 | } 33 | 34 | @Override 35 | public void visitInsn(int opcode) { 36 | super.visitInsn(opcode); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /asm-demo/plugin/src/main/java/com/jeremyliao/android/plugin/OnDestroyMethodVisitor.java: -------------------------------------------------------------------------------- 1 | package com.jeremyliao.android.plugin; 2 | 3 | import org.objectweb.asm.MethodVisitor; 4 | import org.objectweb.asm.Opcodes; 5 | 6 | /** 7 | * Created by liaohailiang on 2019-09-30. 8 | */ 9 | public class OnDestroyMethodVisitor extends MethodVisitor { 10 | 11 | public OnDestroyMethodVisitor(MethodVisitor mv) { 12 | super(Opcodes.ASM4, mv); 13 | } 14 | 15 | @Override 16 | public void visitCode() { 17 | super.visitCode(); 18 | //方法执行前插入 19 | mv.visitLdcInsn("TAG"); 20 | mv.visitTypeInsn(Opcodes.NEW, "java/lang/StringBuilder"); 21 | mv.visitInsn(Opcodes.DUP); 22 | mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/StringBuilder", "", "()V", false); 23 | mv.visitLdcInsn("-------> onDestroy : "); 24 | mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(Ljava/lang/String;)Ljava/lang/StringBuilder;", false); 25 | mv.visitVarInsn(Opcodes.ALOAD, 0); 26 | mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Object", "getClass", "()Ljava/lang/Class;", false); 27 | mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Class", "getSimpleName", "()Ljava/lang/String;", false); 28 | mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(Ljava/lang/String;)Ljava/lang/StringBuilder;", false); 29 | mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/StringBuilder", "toString", "()Ljava/lang/String;", false); 30 | mv.visitMethodInsn(Opcodes.INVOKESTATIC, "android/util/Log", "i", "(Ljava/lang/String;Ljava/lang/String;)I", false); 31 | mv.visitInsn(Opcodes.POP); 32 | } 33 | 34 | 35 | @Override 36 | public void visitInsn(int opcode) { 37 | super.visitInsn(opcode); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /android-gradle-study/build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | println("Root build.gradle: " + project) 3 | 4 | buildscript { 5 | 6 | repositories { 7 | maven { 8 | url uri('./repo') 9 | } 10 | google() 11 | jcenter() 12 | println("Root build.gradle --> buildscript --> repositories") 13 | } 14 | dependencies { 15 | classpath 'com.android.tools.build:gradle:3.2.1' 16 | classpath "com.jeremyliao.gradle:plugin:0.0.1" 17 | // classpath "com.jeremyliao.gradle:plugin1:0.0.1" 18 | // classpath 'com.jakewharton:butterknife-gradle-plugin:9.0.0-rc3' 19 | println("Root build.gradle --> buildscript --> dependencies") 20 | } 21 | } 22 | 23 | allprojects { 24 | repositories { 25 | google() 26 | jcenter() 27 | println("Root build.gradle --> allprojects --> repositories") 28 | } 29 | } 30 | 31 | beforeEvaluate { 32 | project -> 33 | println("beforeEvaluate: $project") 34 | } 35 | 36 | afterEvaluate { 37 | project -> 38 | println("afterEvaluate: $project") 39 | } 40 | 41 | task clean(type: Delete) { 42 | delete rootProject.buildDir 43 | } 44 | 45 | task doNothing(group: 'demo') { 46 | description 'task doNothing' 47 | println("config task doNothing") 48 | afterEvaluate { 49 | println 'doNothing afterEvaluate' 50 | } 51 | doLast { 52 | println "execute task doNothing" 53 | } 54 | } 55 | 56 | task doSomethingAfterAssemble(group: 'demo') { 57 | doLast { 58 | println "execute task doSomethingAfterAssemble" 59 | } 60 | dependsOn('app:assemble') 61 | } 62 | 63 | apply from: 'groovy_test.gradle' 64 | 65 | println("Root build.gradle getScriptClassPath: " + project.buildscript.getScriptClassPath()) 66 | 67 | ext { 68 | root_project_ext_pro = 'hello' 69 | } 70 | 71 | println("root_project_ext_pro: " + root_project_ext_pro) -------------------------------------------------------------------------------- /asm-demo/plugin/src/main/java/com/jeremyliao/android/plugin/TestClassVisitor.java: -------------------------------------------------------------------------------- 1 | package com.jeremyliao.android.plugin; 2 | 3 | import org.objectweb.asm.ClassVisitor; 4 | import org.objectweb.asm.MethodVisitor; 5 | import org.objectweb.asm.Opcodes; 6 | 7 | /** 8 | * Created by liaohailiang on 2019-09-30. 9 | */ 10 | public class TestClassVisitor extends ClassVisitor implements Opcodes { 11 | 12 | private String mClassName; 13 | 14 | public TestClassVisitor(ClassVisitor cv) { 15 | super(Opcodes.ASM5, cv); 16 | } 17 | 18 | @Override 19 | public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) { 20 | //System.out.println("LifecycleClassVisitor : visit -----> started :" + name); 21 | this.mClassName = name; 22 | super.visit(version, access, name, signature, superName, interfaces); 23 | } 24 | 25 | @Override 26 | public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { 27 | //System.out.println("LifecycleClassVisitor : visitMethod : " + name); 28 | MethodVisitor mv = cv.visitMethod(access, name, desc, signature, exceptions); 29 | //匹配FragmentActivity 30 | if ("android/support/v4/app/FragmentActivity".equals(this.mClassName)) { 31 | if ("onCreate".equals(name)) { 32 | //处理onCreate 33 | System.out.println("LifecycleClassVisitor : change method ----> " + name); 34 | return new OnCreateMethodVisitor(mv); 35 | } else if ("onDestroy".equals(name)) { 36 | //处理onDestroy 37 | System.out.println("LifecycleClassVisitor : change method ----> " + name); 38 | return new OnDestroyMethodVisitor(mv); 39 | } 40 | } 41 | return mv; 42 | } 43 | 44 | @Override 45 | public void visitEnd() { 46 | //System.out.println("LifecycleClassVisitor : visit -----> end"); 47 | super.visitEnd(); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /asm-demo/app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /aspectj-demo/app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /javassist-demo/app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /android-gradle-study/app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /android-gradle-study/plugin/src/main/groovy/com/jeremyliao/plugin/AgsGroovyPlugin.groovy: -------------------------------------------------------------------------------- 1 | package com.jeremyliao.plugin 2 | 3 | import com.android.build.gradle.AppExtension 4 | import com.jeremyliao.transform.AgsTransform 5 | import org.gradle.api.Plugin 6 | import org.gradle.api.Project 7 | import org.gradle.api.Task 8 | 9 | /** 10 | * Created by liaohailiang on 2018/12/26. 11 | */ 12 | class AgsGroovyPlugin implements Plugin { 13 | 14 | final String TAG = "[AgsGroovyPlugin]" 15 | 16 | @Override 17 | void apply(Project project) { 18 | System.out.println(TAG + project) 19 | addNewTask(project) 20 | configAfterEvaluate(project) 21 | addTransform(project) 22 | } 23 | 24 | private void addNewTask(Project project) { 25 | //添加一个新的task 26 | project.task('group': 'demo', 'demo') << { 27 | System.out.println(TAG + "execute task demo") 28 | } 29 | } 30 | 31 | private void configAfterEvaluate(Project project) { 32 | project.afterEvaluate { 33 | System.out.println(TAG + "execute afterEvaluate: " + project) 34 | def extension = project.extensions.findByType(AppExtension.class) 35 | extension.applicationVariants.all { variant -> 36 | String variantName = capitalize(variant.getName()) 37 | Task mergeJavaResTask = project.tasks.findByName( 38 | "transformResourcesWithMergeJavaResFor" + variantName) 39 | System.out.println(TAG + "mergeJavaResTask: " + mergeJavaResTask) 40 | mergeJavaResTask.doLast { 41 | System.out.println(TAG + "mergeJavaResTask.doLast execute") 42 | } 43 | } 44 | } 45 | } 46 | 47 | private void addTransform(Project project) { 48 | def extension = project.extensions.findByType(AppExtension.class) 49 | System.out.println(TAG + extension) 50 | extension.registerTransform(new AgsTransform()) 51 | } 52 | 53 | private String capitalize(CharSequence str) { 54 | return (str == null || str.length() == 0) ? "" : "" + Character.toUpperCase(str.charAt(0)) + str.subSequence(1, str.length()) 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /android-gradle-study/plugin/src/main/groovy/com/jeremyliao/transform/AgsTransform.groovy: -------------------------------------------------------------------------------- 1 | package com.jeremyliao.transform 2 | 3 | import com.android.build.api.transform.* 4 | import com.android.build.gradle.internal.pipeline.TransformManager 5 | 6 | import java.util.function.Consumer 7 | import java.util.jar.JarEntry 8 | import java.util.jar.JarFile 9 | 10 | /** 11 | * Created by liaohailiang on 2018/12/26. 12 | */ 13 | class AgsTransform extends Transform { 14 | 15 | final String TAG = "[AgsTransform]" 16 | 17 | @Override 18 | void transform(TransformInvocation transformInvocation) throws TransformException, InterruptedException, IOException { 19 | System.out.println(TAG + "start transform") 20 | super.transform(transformInvocation) 21 | //处理输入 22 | System.out.println(TAG + "处理输入") 23 | for (TransformInput input : transformInvocation.inputs) { 24 | input.jarInputs.parallelStream().forEach(new Consumer() { 25 | @Override 26 | void accept(JarInput jarInput) { 27 | File file = jarInput.getFile() 28 | JarFile jarFile = new JarFile(file) 29 | Enumeration entries = jarFile.entries() 30 | while (entries.hasMoreElements()) { 31 | JarEntry entry = entries.nextElement() 32 | // System.out.println(TAG + "JarEntry: " + entry) 33 | } 34 | } 35 | }) 36 | } 37 | //处理输出 38 | System.out.println(TAG + "处理输出") 39 | File dest = transformInvocation.outputProvider.getContentLocation( 40 | "output_name", 41 | TransformManager.CONTENT_CLASS, 42 | TransformManager.PROJECT_ONLY, 43 | Format.DIRECTORY) 44 | } 45 | 46 | @Override 47 | String getName() { 48 | return AgsTransform.simpleName 49 | } 50 | 51 | @Override 52 | Set getInputTypes() { 53 | return TransformManager.CONTENT_CLASS 54 | } 55 | 56 | @Override 57 | Set getScopes() { 58 | return TransformManager.SCOPE_FULL_PROJECT 59 | } 60 | 61 | @Override 62 | boolean isIncremental() { 63 | return false 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /asm-demo/gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /aspectj-demo/gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /javassist-demo/gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /android-gradle-study/gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /asm-demo/plugin/src/main/java/com/jeremyliao/android/plugin/PrintLogClassVisitor.java: -------------------------------------------------------------------------------- 1 | package com.jeremyliao.android.plugin; 2 | 3 | import com.jeremyliao.android.base.annotation.PrintLog; 4 | 5 | import org.objectweb.asm.AnnotationVisitor; 6 | import org.objectweb.asm.ClassVisitor; 7 | import org.objectweb.asm.MethodVisitor; 8 | import org.objectweb.asm.Opcodes; 9 | import org.objectweb.asm.commons.AdviceAdapter; 10 | import org.objectweb.asm.Type; 11 | 12 | /** 13 | * Created by liaohailiang on 2019-09-30. 14 | */ 15 | public class PrintLogClassVisitor extends ClassVisitor implements Opcodes { 16 | 17 | private String className; 18 | private boolean inject = false; 19 | 20 | public PrintLogClassVisitor(ClassVisitor cv) { 21 | super(Opcodes.ASM5, cv); 22 | } 23 | 24 | @Override 25 | public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) { 26 | this.className = name; 27 | super.visit(version, access, name, signature, superName, interfaces); 28 | } 29 | 30 | @Override 31 | public AnnotationVisitor visitAnnotation(String desc, boolean b) { 32 | if (Type.getDescriptor(PrintLog.class).equals(desc)) { 33 | inject = true; 34 | } 35 | return super.visitAnnotation(desc, b); 36 | } 37 | 38 | @Override 39 | public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { 40 | MethodVisitor mv = cv.visitMethod(access, name, desc, signature, exceptions); 41 | if (!inject) { 42 | return mv; 43 | } 44 | return new AdviceAdapter(Opcodes.ASM5, mv, access, name, desc) { 45 | 46 | @Override 47 | public AnnotationVisitor visitAnnotation(String s, boolean b) { 48 | return super.visitAnnotation(s, b); 49 | } 50 | 51 | @Override 52 | protected void onMethodEnter() { 53 | super.onMethodEnter(); 54 | mv.visitLdcInsn("PrintLog"); 55 | mv.visitLdcInsn("enter method"); 56 | mv.visitMethodInsn(INVOKESTATIC, "android/util/Log", "d", "(Ljava/lang/String;Ljava/lang/String;)I", false); 57 | mv.visitInsn(POP); 58 | } 59 | 60 | @Override 61 | protected void onMethodExit(int i) { 62 | super.onMethodExit(i); 63 | mv.visitLdcInsn("PrintLog"); 64 | mv.visitLdcInsn("exit method"); 65 | mv.visitMethodInsn(INVOKESTATIC, "android/util/Log", "d", "(Ljava/lang/String;Ljava/lang/String;)I", false); 66 | mv.visitInsn(POP); 67 | } 68 | }; 69 | } 70 | 71 | @Override 72 | public void visitEnd() { 73 | super.visitEnd(); 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /android-gradle-study/plugin/src/main/groovy/com/jeremyliao/plugin/DynamicClasspathPlugin.groovy: -------------------------------------------------------------------------------- 1 | package com.jeremyliao.plugin 2 | 3 | 4 | import org.gradle.api.Plugin 5 | import org.gradle.api.Project 6 | 7 | /** 8 | * Created by liaohailiang on 2018/12/26. 9 | * 动态添加classpath的例子 10 | */ 11 | class DynamicClasspathPlugin implements Plugin { 12 | 13 | final String TAG = "[DynamicClasspathPlugin]" 14 | final String BUTTERKNIFE_PLUGIN_NAME = "com.jakewharton:butterknife-gradle-plugin:%s" 15 | final String PLUGIN1_NAME = "com.jeremyliao.gradle:plugin1:%s" 16 | final String USER_REPOSITORIES = null 17 | 18 | @Override 19 | void apply(Project project) { 20 | System.out.println(TAG + project) 21 | addDependencies(project) 22 | } 23 | 24 | private void addDependencies(Project project) { 25 | def props = new Properties() 26 | props.load(project.rootProject.file('gradle.properties').newDataInputStream()) 27 | 28 | def rootClassPath = project.rootProject.buildscript.getScriptClassPath() 29 | System.out.println(TAG + "rootClassPath: " + rootClassPath) 30 | 31 | project.buildscript { 32 | //添加repo 33 | project.buildscript.repositories { 34 | //如果需要,添加自定义的repo 35 | if (USER_REPOSITORIES != null && USER_REPOSITORIES.length() > 0) { 36 | project.buildscript.repositories.maven { 37 | url USER_REPOSITORIES 38 | } 39 | } 40 | //把root project中的repo添加进来 41 | project.buildscript.repositories.addAll(project.rootProject.buildscript.repositories) 42 | } 43 | //添加classpath 44 | project.buildscript.dependencies { 45 | //动态添加两个classpath 46 | def butterknifePlugin = sprintf(BUTTERKNIFE_PLUGIN_NAME, props.getProperty("BUTTERKNIFE_PLUGIN_VERSION")) 47 | def plugins1 = sprintf(PLUGIN1_NAME, props.getProperty("PLUGIN1_VERSION")) 48 | project.buildscript.dependencies.classpath(butterknifePlugin) 49 | project.buildscript.dependencies.classpath(plugins1) 50 | //添加完之后,还要把root project中的classpath添加进来 51 | getRootDependencies(project).all { 52 | dependency -> 53 | def classpath = sprintf("%s:%s:%s", dependency.group, dependency.name, dependency.version) 54 | System.out.println(TAG + "add classpath: " + classpath) 55 | project.buildscript.dependencies.classpath(classpath) 56 | } 57 | } 58 | } 59 | } 60 | 61 | private def getRootDependencies(Project project) { 62 | def clazz = Class.forName("org.gradle.api.internal.initialization.DefaultScriptHandler") 63 | def field = clazz.getDeclaredField("classpathConfiguration") 64 | field.setAccessible(true) 65 | def classpathConfiguration = field.get(project.rootProject.buildscript) 66 | def rootDependencies = classpathConfiguration.getAllDependencies() 67 | System.out.println(TAG + "rootDependencies: " + rootDependencies) 68 | return rootDependencies 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /aspectj-demo/plugin/src/main/groovy/com/jeremyliao/android/plugin/AspectJPlugin.groovy: -------------------------------------------------------------------------------- 1 | package com.jeremyliao.android.plugin 2 | 3 | import com.android.build.gradle.AppPlugin 4 | import com.android.build.gradle.LibraryPlugin 5 | import org.aspectj.bridge.IMessage 6 | import org.aspectj.bridge.MessageHandler 7 | import org.aspectj.tools.ajc.Main 8 | import org.gradle.api.Plugin 9 | import org.gradle.api.Project 10 | import org.gradle.api.tasks.compile.JavaCompile 11 | 12 | /** 13 | * Created by liaohailiang on 2018/12/26. 14 | */ 15 | class AspectJPlugin implements Plugin { 16 | 17 | @Override 18 | void apply(Project project) { 19 | 20 | def hasApp = project.plugins.withType(AppPlugin) 21 | def hasLib = project.plugins.withType(LibraryPlugin) 22 | if (!hasApp && !hasLib) { 23 | throw new IllegalStateException("'android' or 'android-library' plugin required.") 24 | } 25 | 26 | final def log = project.logger 27 | final def variants 28 | if (hasApp) { 29 | variants = project.android.applicationVariants 30 | } else { 31 | variants = project.android.libraryVariants 32 | } 33 | 34 | project.dependencies { 35 | implementation 'org.aspectj:aspectjrt:1.9.1' 36 | } 37 | 38 | variants.all { variant -> 39 | JavaCompile javaCompile = variant.javaCompile 40 | javaCompile.doLast { 41 | String[] args = ["-showWeaveInfo", 42 | "-1.7", 43 | "-inpath", javaCompile.destinationDir.toString(), 44 | "-aspectpath", javaCompile.classpath.asPath, 45 | "-d", javaCompile.destinationDir.toString(), 46 | "-classpath", javaCompile.classpath.asPath, 47 | "-bootclasspath", project.android.bootClasspath.join(File.pathSeparator)] 48 | def argsStr = Arrays.toString(args) 49 | 50 | println("ajc args: " + argsStr) 51 | log.debug "ajc args: " + Arrays.toString(args) 52 | 53 | MessageHandler handler = new MessageHandler(true) 54 | new Main().run(args, handler) 55 | for (IMessage message : handler.getMessages(null, true)) { 56 | switch (message.getKind()) { 57 | case IMessage.ABORT: 58 | case IMessage.ERROR: 59 | case IMessage.FAIL: 60 | log.error message.message, message.thrown 61 | break 62 | case IMessage.WARNING: 63 | log.warn message.message, message.thrown 64 | break 65 | case IMessage.INFO: 66 | log.info message.message, message.thrown 67 | break 68 | case IMessage.DEBUG: 69 | log.debug message.message, message.thrown 70 | break 71 | } 72 | } 73 | } 74 | } 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /android-gradle-study/plugin/src/main/groovy/com/jeremyliao/plugin/DependencyPlugin.groovy: -------------------------------------------------------------------------------- 1 | package com.jeremyliao.plugin 2 | 3 | 4 | import org.gradle.api.Plugin 5 | import org.gradle.api.Project 6 | import org.gradle.api.artifacts.Configuration 7 | import org.gradle.api.artifacts.result.DependencyResult 8 | import org.gradle.api.artifacts.result.ResolvedDependencyResult 9 | 10 | /** 11 | * Created by liaohailiang on 2018/12/26. 12 | */ 13 | class DependencyPlugin implements Plugin { 14 | 15 | final String TAG = "[DependencyPlugin]" 16 | final List whiteList = new ArrayList<>() 17 | 18 | @Override 19 | void apply(Project project) { 20 | project.android.applicationVariants.all { variant -> 21 | println(TAG + "variant: " + variant.name) 22 | whiteList.clear() 23 | whiteList.addAll(project.rootProject.file('white_list.prop').readLines()) 24 | project.configurations.each { Configuration configuration -> 25 | if (configuration.name.toLowerCase().contains("${variant.name}runtimeclasspath")) { 26 | configuration.incoming.resolutionResult.root.dependencies.each { DependencyResult dr -> 27 | boolean accept = acceptDependency(new Dependency(dr, null)) 28 | println(TAG + dr.requested.displayName + " : " + accept) 29 | } 30 | } 31 | } 32 | } 33 | } 34 | 35 | private boolean acceptDependency(Dependency dependency) { 36 | def dr = dependency.dependencyResult 37 | if (accept(dr)) { 38 | return true 39 | } 40 | if (dr instanceof ResolvedDependencyResult) { 41 | def rdr = (ResolvedDependencyResult) dr 42 | def dependencies = rdr.selected.dependencies 43 | if (dependencies.size() > 0) { 44 | for (def dep : dependencies) { 45 | def accept = acceptDependency(new Dependency(dep, dependency)) 46 | if (!accept) { 47 | return false 48 | } 49 | } 50 | return true 51 | } 52 | } 53 | println(TAG + "Not accept: " + getDependencyPath(dependency)) 54 | return false 55 | } 56 | 57 | private boolean accept(DependencyResult dr) { 58 | def name = dr.requested.displayName 59 | for (String dependency : whiteList) { 60 | if (name == dependency) { 61 | return true 62 | } 63 | } 64 | return false 65 | } 66 | 67 | private String getDependencyPath(Dependency dependency) { 68 | List strings = new ArrayList<>() 69 | Dependency current = dependency 70 | while (current != null) { 71 | strings.add(0, current.dependencyResult.requested.displayName) 72 | current = current.previousDependency 73 | } 74 | StringBuilder sb = new StringBuilder() 75 | for (int i = 0; i < strings.size(); i++) { 76 | sb.append(strings.get(i)) 77 | if (i < strings.size() - 1) { 78 | sb.append(" --> ") 79 | } 80 | } 81 | return sb.toString(); 82 | } 83 | 84 | static class Dependency { 85 | final DependencyResult dependencyResult 86 | final Dependency previousDependency 87 | 88 | Dependency(DependencyResult dependencyResult, Dependency previousDependency) { 89 | this.dependencyResult = dependencyResult 90 | this.previousDependency = previousDependency 91 | } 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /android-gradle-study/app/build.gradle: -------------------------------------------------------------------------------- 1 | println("App build.gradle: " + project) 2 | 3 | ext { 4 | ext_pro = 'hello' 5 | } 6 | 7 | apply plugin: 'com.android.application' 8 | buildscript { 9 | apply plugin: 'classpath-plugin' 10 | } 11 | apply plugin: 'ags-groovy-plugin' 12 | apply plugin: 'ags-java-plugin' 13 | apply plugin: 'ags-test-plugin' 14 | apply plugin: 'dependency-plugin' 15 | apply plugin: 'property-read-plugin' 16 | apply plugin: 'com.jakewharton.butterknife' 17 | apply from: rootProject.file('tools.gradle') 18 | 19 | demoConfig { 20 | enable = true 21 | message = 'hello world' 22 | strings = ['a', 'b'] 23 | } 24 | 25 | android { 26 | compileSdkVersion 28 27 | defaultConfig { 28 | applicationId "com.jeremyliao.gradle" 29 | minSdkVersion 15 30 | targetSdkVersion 28 31 | versionCode 1 32 | versionName "1.0" 33 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 34 | } 35 | buildTypes { 36 | debug { 37 | minifyEnabled false 38 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 39 | } 40 | 41 | release { 42 | minifyEnabled true 43 | shrinkResources true 44 | zipAlignEnabled true 45 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 46 | } 47 | } 48 | compileOptions { 49 | sourceCompatibility 1.8 50 | targetCompatibility 1.8 51 | } 52 | } 53 | 54 | dependencies { 55 | implementation fileTree(dir: 'libs', include: ['*.jar']) 56 | implementation 'com.android.support:appcompat-v7:28.0.0' 57 | implementation 'com.android.support.constraint:constraint-layout:1.1.3' 58 | implementation 'com.jakewharton:butterknife:9.0.0' 59 | annotationProcessor 'com.jakewharton:butterknife-compiler:9.0.0' 60 | implementation project(path: ':testlibrary') 61 | } 62 | 63 | 64 | project.android.applicationVariants.all { variant -> 65 | System.out.println("[TEST]" + "variant: " + variant) 66 | def packageTask = project.tasks.findByName("package${variant.name.capitalize()}") 67 | System.out.println("[TEST]" + "packageTask: " + packageTask) 68 | packageTask.doFirst { 69 | def clazz = Class.forName("com.android.builder.model.Version") 70 | def field = clazz.getDeclaredField("ANDROID_GRADLE_PLUGIN_VERSION") 71 | field.setAccessible(true) 72 | version = field.get(null) 73 | System.out.println("[TEST]" + "22version: " + version) 74 | } 75 | } 76 | 77 | //project.android.applicationVariants.all { variant -> 78 | // System.out.println("[DEPENDENCY]" + "variant: " + variant.name) 79 | // project.configurations.each { Configuration configuration -> 80 | // System.out.println("[DEPENDENCY]" + "configuration: " + configuration) 81 | // if (configuration.name.toLowerCase().contains("${variant.name}runtimeclasspath")) { 82 | // configuration.incoming.resolutionResult.root.dependencies.each { DependencyResult dr -> 83 | // System.out.println("[DEPENDENCY]" + "DependencyResult: " + dr) 84 | // if (dr instanceof ResolvedDependencyResult) { 85 | // def rdr = (ResolvedDependencyResult) dr 86 | // rdr.selected.dependencies.each { DependencyResult dependencyResult -> 87 | // System.out.println("[DEPENDENCY]" + "DependencyResult: " + dependencyResult) 88 | // } 89 | // } 90 | // } 91 | // } 92 | // } 93 | //} 94 | 95 | println("app build.gradle getScriptClassPath: " + project.buildscript.getScriptClassPath()) 96 | println("root_project_ext_pro in module: " + root_project_ext_pro) 97 | println("getTimeStamp: " + getTimeStamp()) -------------------------------------------------------------------------------- /aspectj-demo/base/src/main/java/com/jeremyliao/android/base/aspect/PrintLogAspect.java: -------------------------------------------------------------------------------- 1 | package com.jeremyliao.android.base.aspect; 2 | 3 | import android.os.Build; 4 | import android.os.Looper; 5 | import android.os.Trace; 6 | import android.util.Log; 7 | 8 | import org.aspectj.lang.JoinPoint; 9 | import org.aspectj.lang.ProceedingJoinPoint; 10 | import org.aspectj.lang.Signature; 11 | import org.aspectj.lang.annotation.Around; 12 | import org.aspectj.lang.annotation.Aspect; 13 | import org.aspectj.lang.annotation.Pointcut; 14 | import org.aspectj.lang.reflect.CodeSignature; 15 | import org.aspectj.lang.reflect.MethodSignature; 16 | 17 | import java.util.concurrent.TimeUnit; 18 | 19 | /** 20 | * Created by liaohailiang on 2019-09-26. 21 | *

22 | * 验证Hugo的代码,顺便熟悉Aspect 23 | */ 24 | @Aspect 25 | public class PrintLogAspect { 26 | 27 | @Pointcut("within(@com.jeremyliao.android.base.annotation.PrintLog *)") 28 | public void withinAnnotatedClass() { 29 | } 30 | 31 | 32 | @Pointcut("execution(!synthetic * *(..)) && withinAnnotatedClass()") 33 | public void methodInsideAnnotatedType() { 34 | } 35 | 36 | @Pointcut("execution(!synthetic *.new(..)) && withinAnnotatedClass()") 37 | public void constructorInsideAnnotatedType() { 38 | } 39 | 40 | @Pointcut("execution(@com.jeremyliao.android.base.annotation.PrintLog * *(..)) || methodInsideAnnotatedType()") 41 | public void method() { 42 | } 43 | 44 | @Pointcut("execution(@com.jeremyliao.android.base.annotation.PrintLog *.new(..)) || constructorInsideAnnotatedType()") 45 | public void constructor() { 46 | } 47 | 48 | @Around("method() || constructor()") 49 | public Object logAndExecute(ProceedingJoinPoint joinPoint) throws Throwable { 50 | enterMethod(joinPoint); 51 | 52 | long startNanos = System.nanoTime(); 53 | Object result = joinPoint.proceed(); 54 | long stopNanos = System.nanoTime(); 55 | long lengthMillis = TimeUnit.NANOSECONDS.toMillis(stopNanos - startNanos); 56 | 57 | exitMethod(joinPoint, result, lengthMillis); 58 | 59 | return result; 60 | } 61 | 62 | private static void enterMethod(JoinPoint joinPoint) { 63 | CodeSignature codeSignature = (CodeSignature) joinPoint.getSignature(); 64 | 65 | Class cls = codeSignature.getDeclaringType(); 66 | String methodName = codeSignature.getName(); 67 | String[] parameterNames = codeSignature.getParameterNames(); 68 | Object[] parameterValues = joinPoint.getArgs(); 69 | 70 | StringBuilder builder = new StringBuilder("\u21E2 "); 71 | builder.append(methodName).append('('); 72 | for (int i = 0; i < parameterValues.length; i++) { 73 | if (i > 0) { 74 | builder.append(", "); 75 | } 76 | builder.append(parameterNames[i]).append('='); 77 | builder.append(parameterValues[i]); 78 | } 79 | builder.append(')'); 80 | 81 | if (Looper.myLooper() != Looper.getMainLooper()) { 82 | builder.append(" [Thread:\"").append(Thread.currentThread().getName()).append("\"]"); 83 | } 84 | 85 | Log.v(asTag(cls), builder.toString()); 86 | 87 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { 88 | final String section = builder.toString().substring(2); 89 | Trace.beginSection(section); 90 | } 91 | } 92 | 93 | private static void exitMethod(JoinPoint joinPoint, Object result, long lengthMillis) { 94 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { 95 | Trace.endSection(); 96 | } 97 | 98 | Signature signature = joinPoint.getSignature(); 99 | 100 | Class cls = signature.getDeclaringType(); 101 | String methodName = signature.getName(); 102 | boolean hasReturnType = signature instanceof MethodSignature 103 | && ((MethodSignature) signature).getReturnType() != void.class; 104 | 105 | StringBuilder builder = new StringBuilder("\u21E0 ") 106 | .append(methodName) 107 | .append(" [") 108 | .append(lengthMillis) 109 | .append("ms]"); 110 | 111 | if (hasReturnType) { 112 | builder.append(" = "); 113 | builder.append(result); 114 | } 115 | 116 | Log.v(asTag(cls), builder.toString()); 117 | } 118 | 119 | private static String asTag(Class cls) { 120 | if (cls.isAnonymousClass()) { 121 | return asTag(cls.getEnclosingClass()); 122 | } 123 | return cls.getSimpleName(); 124 | } 125 | } 126 | -------------------------------------------------------------------------------- /asm-demo/gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn () { 37 | echo "$*" 38 | } 39 | 40 | die () { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save () { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /aspectj-demo/gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn () { 37 | echo "$*" 38 | } 39 | 40 | die () { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save () { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /javassist-demo/gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn () { 37 | echo "$*" 38 | } 39 | 40 | die () { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save () { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /android-gradle-study/gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn () { 37 | echo "$*" 38 | } 39 | 40 | die () { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save () { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /asm-demo/app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 | 65 | 70 | 75 | 80 | 85 | 90 | 95 | 100 | 105 | 110 | 115 | 120 | 125 | 130 | 135 | 140 | 145 | 150 | 155 | 160 | 165 | 170 | 171 | -------------------------------------------------------------------------------- /aspectj-demo/app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 | 65 | 70 | 75 | 80 | 85 | 90 | 95 | 100 | 105 | 110 | 115 | 120 | 125 | 130 | 135 | 140 | 145 | 150 | 155 | 160 | 165 | 170 | 171 | -------------------------------------------------------------------------------- /javassist-demo/app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 | 65 | 70 | 75 | 80 | 85 | 90 | 95 | 100 | 105 | 110 | 115 | 120 | 125 | 130 | 135 | 140 | 145 | 150 | 155 | 160 | 165 | 170 | 171 | -------------------------------------------------------------------------------- /android-gradle-study/app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 | 65 | 70 | 75 | 80 | 85 | 90 | 95 | 100 | 105 | 110 | 115 | 120 | 125 | 130 | 135 | 140 | 145 | 150 | 155 | 160 | 165 | 170 | 171 | -------------------------------------------------------------------------------- /asm-demo/plugin/src/main/groovy/com/jeremyliao/android/plugin/transform/PrintLogTransform.groovy: -------------------------------------------------------------------------------- 1 | package com.jeremyliao.android.plugin.transform 2 | 3 | import com.android.build.api.transform.* 4 | import com.android.build.gradle.internal.pipeline.TransformManager 5 | import com.android.utils.FileUtils 6 | import com.jeremyliao.android.plugin.PrintLogClassVisitor 7 | import com.jeremyliao.android.plugin.TestClassVisitor 8 | import org.objectweb.asm.ClassReader 9 | import org.objectweb.asm.ClassVisitor 10 | import org.objectweb.asm.ClassWriter 11 | import org.apache.commons.codec.digest.DigestUtils 12 | import org.apache.commons.io.IOUtils 13 | 14 | import java.util.jar.JarEntry 15 | import java.util.jar.JarFile 16 | import java.util.jar.JarOutputStream 17 | import java.util.zip.ZipEntry 18 | import static org.objectweb.asm.ClassReader.EXPAND_FRAMES 19 | 20 | /** 21 | * Created by liaohailiang on 2018/12/26. 22 | */ 23 | class PrintLogTransform extends Transform { 24 | 25 | final String TAG = "[PrintLogTransform]" 26 | 27 | @Override 28 | void transform(TransformInvocation transformInvocation) throws TransformException, InterruptedException, IOException { 29 | System.out.println(TAG + "start transform") 30 | super.transform(transformInvocation) 31 | Collection inputs = transformInvocation.inputs 32 | TransformOutputProvider outputProvider = transformInvocation.outputProvider 33 | 34 | //删除之前的输出 35 | if (outputProvider != null) 36 | outputProvider.deleteAll() 37 | //遍历inputs 38 | inputs.each { TransformInput input -> 39 | //遍历directoryInputs 40 | input.directoryInputs.each { DirectoryInput directoryInput -> 41 | //处理directoryInputs 42 | handleDirectoryInput(directoryInput, outputProvider) 43 | } 44 | 45 | //遍历jarInputs 46 | input.jarInputs.each { JarInput jarInput -> 47 | //处理jarInputs 48 | handleJarInputs(jarInput, outputProvider) 49 | } 50 | } 51 | } 52 | 53 | @Override 54 | String getName() { 55 | return PrintLogTransform.simpleName 56 | } 57 | 58 | @Override 59 | Set getInputTypes() { 60 | return TransformManager.CONTENT_CLASS 61 | } 62 | 63 | @Override 64 | Set getScopes() { 65 | return TransformManager.SCOPE_FULL_PROJECT 66 | } 67 | 68 | @Override 69 | boolean isIncremental() { 70 | return false 71 | } 72 | 73 | /** 74 | * 处理文件目录下的class文件 75 | */ 76 | static void handleDirectoryInput(DirectoryInput directoryInput, TransformOutputProvider outputProvider) { 77 | //是否是目录 78 | if (directoryInput.file.isDirectory()) { 79 | //列出目录所有文件(包含子文件夹,子文件夹内文件) 80 | directoryInput.file.eachFileRecurse { File file -> 81 | def name = file.name 82 | if (name.endsWith(".class") && !name.startsWith("R\$") && 83 | !"R.class".equals(name) && !"BuildConfig.class".equals(name)) { 84 | println 'filename: ' + name 85 | ClassReader classReader = new ClassReader(file.bytes) 86 | ClassWriter classWriter = new ClassWriter(classReader, ClassWriter.COMPUTE_MAXS) 87 | ClassVisitor cv = new PrintLogClassVisitor(classWriter) 88 | classReader.accept(cv, EXPAND_FRAMES) 89 | byte[] code = classWriter.toByteArray() 90 | FileOutputStream fos = new FileOutputStream( 91 | file.parentFile.absolutePath + File.separator + name) 92 | fos.write(code) 93 | fos.close() 94 | } 95 | } 96 | } 97 | //处理完输入文件之后,要把输出给下一个任务 98 | def dest = outputProvider.getContentLocation(directoryInput.name, 99 | directoryInput.contentTypes, directoryInput.scopes, 100 | Format.DIRECTORY) 101 | FileUtils.copyDirectory(directoryInput.file, dest) 102 | } 103 | 104 | /** 105 | * 处理Jar中的class文件 106 | */ 107 | static void handleJarInputs(JarInput jarInput, TransformOutputProvider outputProvider) { 108 | if (jarInput.file.getAbsolutePath().endsWith(".jar")) { 109 | //重名名输出文件,因为可能同名,会覆盖 110 | def jarName = jarInput.name 111 | def md5Name = DigestUtils.md5Hex(jarInput.file.getAbsolutePath()) 112 | if (jarName.endsWith(".jar")) { 113 | jarName = jarName.substring(0, jarName.length() - 4) 114 | } 115 | JarFile jarFile = new JarFile(jarInput.file) 116 | Enumeration enumeration = jarFile.entries() 117 | File tmpFile = new File(jarInput.file.getParent() + File.separator + "classes_temp.jar") 118 | //避免上次的缓存被重复插入 119 | if (tmpFile.exists()) { 120 | tmpFile.delete() 121 | } 122 | JarOutputStream jarOutputStream = new JarOutputStream(new FileOutputStream(tmpFile)) 123 | //用于保存 124 | while (enumeration.hasMoreElements()) { 125 | JarEntry jarEntry = (JarEntry) enumeration.nextElement() 126 | String entryName = jarEntry.getName() 127 | ZipEntry zipEntry = new ZipEntry(entryName) 128 | InputStream inputStream = jarFile.getInputStream(jarEntry) 129 | //插桩class 130 | if (entryName.endsWith(".class") && !entryName.startsWith("R\$") 131 | && !"R.class".equals(entryName) && !"BuildConfig.class".equals(entryName) 132 | && "android/support/v4/app/FragmentActivity.class".equals(entryName)) { 133 | //class文件处理 134 | println '----------- deal with "jar" class file <' + entryName + '> -----------' 135 | jarOutputStream.putNextEntry(zipEntry) 136 | ClassReader classReader = new ClassReader(IOUtils.toByteArray(inputStream)) 137 | ClassWriter classWriter = new ClassWriter(classReader, ClassWriter.COMPUTE_MAXS) 138 | ClassVisitor cv = new TestClassVisitor(classWriter) 139 | classReader.accept(cv, EXPAND_FRAMES) 140 | byte[] code = classWriter.toByteArray() 141 | jarOutputStream.write(code) 142 | } else { 143 | jarOutputStream.putNextEntry(zipEntry) 144 | jarOutputStream.write(IOUtils.toByteArray(inputStream)) 145 | } 146 | jarOutputStream.closeEntry() 147 | } 148 | //结束 149 | jarOutputStream.close() 150 | jarFile.close() 151 | def dest = outputProvider.getContentLocation(jarName + md5Name, 152 | jarInput.contentTypes, jarInput.scopes, Format.JAR) 153 | FileUtils.copyFile(tmpFile, dest) 154 | tmpFile.delete() 155 | } 156 | } 157 | } 158 | -------------------------------------------------------------------------------- /javassist-demo/plugin/src/main/groovy/com/jeremyliao/android/plugin/transform/PrintLogTransform.groovy: -------------------------------------------------------------------------------- 1 | package com.jeremyliao.android.plugin.transform 2 | 3 | import com.android.build.api.transform.* 4 | import com.android.build.gradle.internal.pipeline.TransformManager 5 | import com.android.utils.FileUtils 6 | import com.jeremyliao.android.base.annotation.PrintLog 7 | import javassist.ClassPool 8 | import javassist.CtClass 9 | import javassist.CtMethod 10 | import org.apache.commons.codec.digest.DigestUtils 11 | import org.apache.commons.io.IOUtils 12 | import org.gradle.api.Project 13 | import org.gradle.api.internal.tasks.testing.detection.TestClassVisitor 14 | import org.objectweb.asm.ClassReader 15 | import org.objectweb.asm.ClassVisitor 16 | import org.objectweb.asm.ClassWriter 17 | 18 | import java.util.jar.JarEntry 19 | import java.util.jar.JarFile 20 | import java.util.jar.JarOutputStream 21 | import java.util.zip.ZipEntry 22 | 23 | import static org.objectweb.asm.ClassReader.EXPAND_FRAMES 24 | 25 | /** 26 | * Created by liaohailiang on 2018/12/26. 27 | */ 28 | class PrintLogTransform extends Transform { 29 | 30 | final String TAG = "[PrintLogTransform]" 31 | 32 | final static ClassPool pool = ClassPool.getDefault() 33 | 34 | final Project project 35 | 36 | PrintLogTransform(Project project) { 37 | this.project = project 38 | } 39 | 40 | @Override 41 | void transform(TransformInvocation transformInvocation) throws TransformException, InterruptedException, IOException { 42 | System.out.println(TAG + "start transform") 43 | super.transform(transformInvocation) 44 | Collection inputs = transformInvocation.inputs 45 | TransformOutputProvider outputProvider = transformInvocation.outputProvider 46 | 47 | //删除之前的输出 48 | if (outputProvider != null) 49 | outputProvider.deleteAll() 50 | //遍历inputs 51 | inputs.each { TransformInput input -> 52 | //遍历directoryInputs 53 | input.directoryInputs.each { DirectoryInput directoryInput -> 54 | //处理directoryInputs 55 | handleDirectoryInput(directoryInput, outputProvider) 56 | } 57 | 58 | //遍历jarInputs 59 | input.jarInputs.each { JarInput jarInput -> 60 | //处理jarInputs 61 | handleJarInputs(jarInput, outputProvider) 62 | } 63 | } 64 | } 65 | 66 | @Override 67 | String getName() { 68 | return PrintLogTransform.simpleName 69 | } 70 | 71 | @Override 72 | Set getInputTypes() { 73 | return TransformManager.CONTENT_CLASS 74 | } 75 | 76 | @Override 77 | Set getScopes() { 78 | return TransformManager.SCOPE_FULL_PROJECT 79 | } 80 | 81 | @Override 82 | boolean isIncremental() { 83 | return false 84 | } 85 | 86 | /** 87 | * 处理文件目录下的class文件 88 | */ 89 | void handleDirectoryInput(DirectoryInput directoryInput, TransformOutputProvider outputProvider) { 90 | //将当前路径加入类池,不然找不到这个类 91 | pool.appendClassPath(directoryInput.file.absolutePath) 92 | pool.appendClassPath(project.android.bootClasspath[0].toString()) 93 | pool.importPackage("android.util.Log") 94 | String packageName = project.android.defaultConfig.applicationId 95 | println 'packageName: ' + packageName 96 | if (directoryInput.file.isDirectory()) { 97 | directoryInput.file.eachFileRecurse { File file -> 98 | def name = file.name 99 | if (name.endsWith(".class") && !name.startsWith("R\$") && 100 | !"R.class".equals(name) && !"BuildConfig.class".equals(name)) { 101 | println 'filename: ' + name 102 | def filePath = file.absolutePath 103 | def filePathWithDot = filePath.replace("\\", ".").replace("/", ".") 104 | int start = filePathWithDot.indexOf(packageName) 105 | println 'start: ' + start 106 | if (start != -1) { 107 | int end = filePath.length() - 6 108 | String className = filePathWithDot.substring(start, end) 109 | println 'className: ' + className 110 | CtClass ctClass = pool.getCtClass(className) 111 | if (ctClass.isFrozen()) { 112 | ctClass.defrost() 113 | } 114 | if (ctClass.hasAnnotation(PrintLog.class)) { 115 | for (CtMethod ctMethod : ctClass.getDeclaredMethods()) { 116 | println 'method: ' + ctMethod 117 | String code = """ android.util.Log.d("PrintLog","enter method"); 118 | """ 119 | ctMethod.insertBefore(code) 120 | code = """ android.util.Log.d("PrintLog","exit method"); 121 | """ 122 | ctMethod.insertAfter(code) 123 | } 124 | } 125 | ctClass.writeFile(directoryInput.file.absolutePath) 126 | ctClass.detach() 127 | } 128 | } 129 | } 130 | } 131 | //处理完输入文件之后,要把输出给下一个任务 132 | def dest = outputProvider.getContentLocation(directoryInput.name, 133 | directoryInput.contentTypes, directoryInput.scopes, 134 | Format.DIRECTORY) 135 | FileUtils.copyDirectory(directoryInput.file, dest) 136 | } 137 | 138 | /** 139 | * 处理Jar中的class文件 140 | */ 141 | static void handleJarInputs(JarInput jarInput, TransformOutputProvider outputProvider) { 142 | if (jarInput.file.getAbsolutePath().endsWith(".jar")) { 143 | //重名名输出文件,因为可能同名,会覆盖 144 | def jarName = jarInput.name 145 | def md5Name = DigestUtils.md5Hex(jarInput.file.getAbsolutePath()) 146 | if (jarName.endsWith(".jar")) { 147 | jarName = jarName.substring(0, jarName.length() - 4) 148 | } 149 | JarFile jarFile = new JarFile(jarInput.file) 150 | Enumeration enumeration = jarFile.entries() 151 | File tmpFile = new File(jarInput.file.getParent() + File.separator + "classes_temp.jar") 152 | //避免上次的缓存被重复插入 153 | if (tmpFile.exists()) { 154 | tmpFile.delete() 155 | } 156 | JarOutputStream jarOutputStream = new JarOutputStream(new FileOutputStream(tmpFile)) 157 | // //用于保存 158 | // while (enumeration.hasMoreElements()) { 159 | // JarEntry jarEntry = (JarEntry) enumeration.nextElement() 160 | // String entryName = jarEntry.getName() 161 | // ZipEntry zipEntry = new ZipEntry(entryName) 162 | // InputStream inputStream = jarFile.getInputStream(jarEntry) 163 | // //插桩class 164 | // if (entryName.endsWith(".class") && !entryName.startsWith("R\$") 165 | // && !"R.class".equals(entryName) && !"BuildConfig.class".equals(entryName) 166 | // && "android/support/v4/app/FragmentActivity.class".equals(entryName)) { 167 | // //class文件处理 168 | // println '----------- deal with "jar" class file <' + entryName + '> -----------' 169 | // jarOutputStream.putNextEntry(zipEntry) 170 | // ClassReader classReader = new ClassReader(IOUtils.toByteArray(inputStream)) 171 | // ClassWriter classWriter = new ClassWriter(classReader, ClassWriter.COMPUTE_MAXS) 172 | // ClassVisitor cv = new TestClassVisitor(classWriter) 173 | // classReader.accept(cv, EXPAND_FRAMES) 174 | // byte[] code = classWriter.toByteArray() 175 | // jarOutputStream.write(code) 176 | // } else { 177 | // jarOutputStream.putNextEntry(zipEntry) 178 | // jarOutputStream.write(IOUtils.toByteArray(inputStream)) 179 | // } 180 | // jarOutputStream.closeEntry() 181 | // } 182 | //结束 183 | jarOutputStream.close() 184 | jarFile.close() 185 | def dest = outputProvider.getContentLocation(jarName + md5Name, 186 | jarInput.contentTypes, jarInput.scopes, Format.JAR) 187 | FileUtils.copyFile(tmpFile, dest) 188 | tmpFile.delete() 189 | } 190 | } 191 | } 192 | --------------------------------------------------------------------------------