{"id":13343081,"url":"https://github.com/7hens/android-x2j","last_synced_at":"2025-03-12T04:32:16.564Z","repository":{"id":41384184,"uuid":"214315552","full_name":"7hens/android-x2j","owner":"7hens","description":"☕ write XML, run Java.","archived":false,"fork":false,"pushed_at":"2022-11-03T01:46:30.000Z","size":282,"stargazers_count":111,"open_issues_count":5,"forks_count":9,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-07-30T21:06:14.386Z","etag":null,"topics":["android","gradle","java","plugin","x2c","x2j","xml","xml-java"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/7hens.png","metadata":{"files":{"readme":"README.en.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-10-11T01:15:26.000Z","updated_at":"2024-07-01T23:54:02.000Z","dependencies_parsed_at":"2023-01-21T01:04:48.288Z","dependency_job_id":null,"html_url":"https://github.com/7hens/android-x2j","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/7hens%2Fandroid-x2j","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/7hens%2Fandroid-x2j/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/7hens%2Fandroid-x2j/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/7hens%2Fandroid-x2j/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/7hens","download_url":"https://codeload.github.com/7hens/android-x2j/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221270031,"owners_count":16788788,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","gradle","java","plugin","x2c","x2j","xml","xml-java"],"created_at":"2024-07-29T19:30:37.071Z","updated_at":"2024-10-24T03:30:22.308Z","avatar_url":"https://github.com/7hens.png","language":"Kotlin","readme":"# Android X2J\n\n[![jitpack](https://jitpack.io/v/7hens/android-x2j.svg)](https://jitpack.io/#7hens/android-x2j)\n[![license](https://img.shields.io/github/license/7hens/android-x2j.svg)](https://github.com/7hens/android-x2j/blob/master/LICENSE)\n[![stars](https://img.shields.io/github/stars/7hens/android-x2j.svg?style=social)](https://github.com/7hens/android-x2j)\n\nWrite XML, run Java !!\n\nAndroid X2J is a Gradle plugin that can translate your XML layouts into Java codes and inject them into Activity and custom layouts during compilation.\n\nIn the traditional case, XML is parsed at runtime (via LayoutInflater), while Android X2J can advance XML parsing to compile time, which can increase layout loading speed by 200%.\n\n## Quick Start\n\n1) in build/gradle.\n\nlast_version: [![jitpack](https://jitpack.io/v/7hens/android-x2j.svg)](https://jitpack.io/#7hens/android-x2j)\n\n```groovy\nbuildscript {\n    repositories {\n        maven { url \"https://jitpack.io\" }\n    }\n    dependencies {\n        classpath 'com.github.7hens:android-x2j:1.5'\n    }\n}\n\nallprojects {\n    repositories {\n        maven { url \"https://jitpack.io\" }\n    }\n}\n```\n\n2) in app/build.gradle.\n\n```groovy\n// make sure this line comes AFTER android {} block.\napply plugin: 'android-x2j'\n\n\n// configure the xml layouts to translate (optional)，\n// all xml layouts are translated by default\nandroidX2J {\n    includes \"activity_.*\", \"dialog_main\"\n    excludes \"fragment_.*\"\n}\n```\n\n\u003e Android X2J supports both application and library modules.\n\n3) Ok, let's hand it over to Android X2J.\n\n## X2J and X2C\n\nAndroid X2J is based on [X2C](https://github.com/iReaderAndroid/X2C).\n__It even allows you to enjoy the X2C functionality without knowing the API and usage of X2C.__\n\nFirst, Android X2J will automatically add X2C dependencies to your dependencies and generate the associated `@Xml` annotations.\n\nSecond, and most importantly, Android X2J uses the gradle transform api to automatically convert the java bytecode as follows during the APP build.\n\n```plain\nactivity.setContentView(R.layout.activity_main)\n=\u003e\u003e X2J.setContentView(activity, R.layout.activity_main)\n\nlayoutInflater.inflate(R.layout.view_item, parent)\n=\u003e\u003e X2J.inflate(layoutInflater, R.layout.view_item, parent)\n\nView.inflate(context, R.layout.view_item, parent)\n=\u003e\u003e X2J.inflate(context, R.layout.view_item, parent)\n```\n\n\u003e `The X2J` class has similar functionality to the `X2C` class.\n\nThe following is the source code of the MainActivity in the sample module:\n\n```java\npublic class MainActivity extends Activity {\n    @Override\n    protected void onCreate(Bundle savedInstanceState) {\n        super.onCreate(savedInstanceState);\n        setContentView(R.layout.activity_main);\n        LayoutInflater.from(this).inflate(R.layout.fragmetn_layout, null);\n        LayoutInflater.from(this).inflate(R.layout.fragmetn_layout, null, false);\n    }\n}\n```\n\nThe following is the corresponding code after apk decompilation using the X2J plugin package:\n\n```java\npublic class MainActivity extends Activity {\n    protected void onCreate(Bundle savedInstanceState) {\n        super.onCreate(savedInstanceState);\n        X2J.setContentView(this, R.layout.activity_main);\n        X2J.inflate(LayoutInflater.from(this), (int) R.layout.fragmetn_layout, null);\n        X2J.inflate(LayoutInflater.from(this), (int) R.layout.fragmetn_layout, null, false);\n    }\n}\n```\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F7hens%2Fandroid-x2j","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F7hens%2Fandroid-x2j","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F7hens%2Fandroid-x2j/lists"}