Skip to content

Commit

Permalink
Add Android readme.
Browse files Browse the repository at this point in the history
  • Loading branch information
raphw committed Oct 6, 2020
1 parent a52b1d1 commit 15b4604
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions byte-buddy-android/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Byte Buddy Android

**Byte Buddy Android** allows you to generate classes on Android and to load them into the current Android VM process. To load classes on Android, the `AndroidClassLoadingStrategy` must be used when loading a dynamic type:

```java
ClassLoadingStrategy strategy = new AndroidClassLoadingStrategy.Wrapping(context.getDir(
"generated",
Context.MODE_PRIVATE));

Class<?> dynamicType = new ByteBuddy()
.subclass(Object.class)
.method(ElementMatchers.named("toString"))
.intercept(FixedValue.value("Hello World!"))
.make()
.load(getClass().getClassLoader(), strategy)
.getLoaded();
assertThat(dynamicType.newInstance().toString(), is("Hello World!"))
```

Using the strategy requires Android with support for API version 21 or later. A wrapping and an injecting class loading strategy is offered, similar to Byte Buddy's standard strategies. On Android, it is not possible to transform loaded classes or to register a Java agent.

0 comments on commit 15b4604

Please sign in to comment.