Skip to content

Commit c32f2b1

Browse files
committed
docs: update README
1 parent acbfa8f commit c32f2b1

File tree

2 files changed

+52
-30
lines changed

2 files changed

+52
-30
lines changed

README.en.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,19 @@
66

77
The missing gradle plugin for [X2C](https://github.com/iReaderAndroid/X2C).
88

9+
Android X2J uses the gradle transform api, which automatically converts the java bytecode as follows during the APP build.
10+
11+
```plain
12+
activity.setContentView(R.layout.activity_main)
13+
=>> X2J.setContentView(activity, R.layout.activity_main)
14+
15+
layoutInflater.inflate(R.layout.view_item, parent)
16+
=>> X2J.inflate(layoutInflater, R.layout.view_item, parent)
17+
18+
View.inflate(context, R.layout.view_item, parent)
19+
=>> X2J.inflate(context, R.layout.view_item, parent)
20+
```
21+
922
## Setting up the dependency
1023

1124
in build/gradle

README.md

Lines changed: 39 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,14 @@
44
[![license](https://img.shields.io/github/license/7hens/android-x2j.svg)](https://github.com/7hens/android-x2j/blob/master/LICENSE)
55
[![stars](https://img.shields.io/github/stars/7hens/android-x2j.svg?style=social)](https://github.com/7hens/android-x2j)
66

7-
Android X2J(XML to Java)是一个 gradle 插件,可以让你零成本使用 [X2C](https://github.com/iReaderAndroid/X2C) (在编译时将你 XML 布局翻译成的 Java 代码)。
7+
让你的 XML 布局变成 Java 来运行 !!
88

9-
Android X2J 使用了 gradle transform api,会在 APP 构建期间自动将 java 字节码做如下转换。
9+
Android X2J(XML to Java)是一个 gradle 插件,可以让你零成本使用 [X2C](https://github.com/iReaderAndroid/X2C) (将 XML 布局翻译成 Java 代码)。
10+
__它甚至可以让你在完全不了解 X2C 的 API 和用法情况下,就可以享受到 X2C 的功能。__
11+
12+
首先,Android X2J 会自动为你在 dependencies 中添加 X2C 的相关依赖,生成相关的 `@Xml` 注解。
13+
14+
其次,当然也是最重要的一点,Android X2J 使用了 gradle transform api,在 APP 构建期间自动将 java 字节码做如下转换。
1015

1116
```plain
1217
activity.setContentView(R.layout.activity_main)
@@ -19,34 +24,7 @@ View.inflate(context, R.layout.view_item, parent)
1924
=>> X2J.inflate(context, R.layout.view_item, parent)
2025
```
2126

22-
> 实际上,`X2J.setContentView` 直接调用了 `X2C.setContentView`。因为 `X2C` 类本身有 bug,所以才有了 `X2J` 类。
23-
24-
!> 注意,因为 X2C 自身的原因,目前 Android X2J 并不支持 kotlin-kapt。
25-
26-
## 使用方法
27-
28-
1) 配置根目录的 build/gradle。
29-
30-
```groovy
31-
buildscript {
32-
repositories {
33-
// ...
34-
maven { url "https://jitpack.io" }
35-
}
36-
dependencies {
37-
classpath 'com.github.7hens:android-x2j:<last_version>'
38-
}
39-
}
40-
```
41-
42-
2) 在 app/build.gradle 中使用插件。
43-
44-
```groovy
45-
// 必须在 android {} 代码块之后添加
46-
apply plugin: 'android-x2j'
47-
```
48-
49-
3) 好了,接下来 Android X2J 会自动把 XML 布局翻译成 Java 代码(当然,这归功于 X2C),并打包到 APK 中。
27+
> `X2J` 类是对 `X2C` 类的封装。
5028
5129
下面是 sample 模块里面的 MainActivity 的源码:
5230

@@ -74,3 +52,34 @@ public class MainActivity extends Activity {
7452
}
7553
}
7654
```
55+
56+
最后,如果你已经使用了 Android X2J 插件然后又想弃坑,这很容易就能做到。
57+
因为它只不过是一个 gradle 插件而已,没有任何侵入性。
58+
59+
!> 注意,目前由于 X2C 自身的限制, Android X2J 并不支持 kotlin-kapt。
60+
61+
## 使用方法
62+
63+
1) 配置根目录的 build/gradle。
64+
65+
```groovy
66+
buildscript {
67+
repositories {
68+
// ...
69+
maven { url "https://jitpack.io" }
70+
}
71+
dependencies {
72+
classpath 'com.github.7hens:android-x2j:<last_version>'
73+
}
74+
}
75+
```
76+
77+
2) 在 app/build.gradle 中使用插件。
78+
79+
```groovy
80+
// 必须在 android {} 代码块之后添加插件。
81+
// 如果你不想使用 X2J 了,把这行注释掉就行了。
82+
apply plugin: 'android-x2j'
83+
```
84+
85+
3) 好了,接下来 Android X2J 会自动把 XML 布局翻译成 Java 代码(当然,这归功于 X2C),并打包到 APK 中。

0 commit comments

Comments
 (0)