Coder Social home page Coder Social logo

android-buddy's People

Contributors

alexanderwert avatar likethesalad avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

android-buddy's Issues

Incremental build often fails

I am running into an issue where an incremental build fails and I have to do a clean build (which succeeds). I am running into this quite often. Did I mess something up during the installation or is this a limitation or bug of this plugin?

I am using the Aaper library so I am not using android-buddy directly.

Schermafbeelding 2020-12-25 om 00 02 27

Change method to return your values

How we could change the returned value of a function?

Let's assume that we have the following class:

class Foo : Bar() {
	
    override fun barMethod(): Baz {
       return super.barMethod()
    }
}

What we want to do is to wrap the result and return the wrapper instead. Something like that:

class Foo : Bar() {
	
    override fun barMethod(): Baz {
        return BazDelegate(super.barMethod())
    }
}

class BazDelegate: Baz() {}

I 've created the interceptor, but the originalMethodCall as described in the example is a Runnable, which means that it does not return anything.

object MyInterceptor {

    @JvmStatic
    fun intercept(
        @SuperCall originalMethodCall: Runnable
    ) {
        originalMethodCall.run()
    }
}

Failed to apply plugin 'android-buddy'.

I'm trying to configure environment for using android-buddy. I found External Libraries has 'com.likethesalad.android:android-buddy-tools:1.1.1' but I got error when insert the [ id ' android-buddy']. Is it changed the method for configure the gradle?

below image : build.gradle(app)

image
image
image

below image : build.gradle(project)
image

Allow to configure custom EntryPoint

I am trying to instrument a rather large application written in Kotlin and ran into some problems with bytecode generated by the Kotlin compiler that is not valid for byte-buddy. For reference, the issue is very similar to this: raphw/byte-buddy#764

The proposed solution is to disable validation using: new ByteBuddy().with(TypeValidation.DISABLED).
But I did not find a way to register a custom EntryPoint or a custom ByteBuddy instance. It would be very helpful to expose an interface where a user can overwrite the configuration of ByteBuddy.

A possible solution might be to expose a new decorator @EntryPoint, allowing android-buddy to find the EntryPoint defined by the user, which might look like this:

@EntryPoint
public class MyEntryPoint implements EntryPoint {

    @Override
    public ByteBuddy byteBuddy(ClassFileVersion classFileVersion) {
        return new ByteBuddy().with(TypeValidation.DISABLED);
    }

    @Override
    public DynamicType.Builder<?> transform(TypeDescription typeDescription, ByteBuddy byteBuddy, ClassFileLocator classFileLocator, MethodNameTransformer methodNameTransformer) {
        return byteBuddy.rebase(typeDescription, classFileLocator, methodNameTransformer);
    }
}

If such an EntryPoint is found, android-buddy could then use an instance of it, instead of the default EntryPoint (as currently done in

).

BTW awesome project :)

Could not intercept Android view method call. What I am doing wrong?

Suppose I have a student class like below
`class Student {

String firstName;
String lastName;

public Student(String firstName, String lastName) {
    this.firstName = firstName;
    this.lastName = lastName;
}

public String getFullName() {
    return firstName + " " + lastName;
}

}`

Now I have created the transformation to intercept getFullName method call like below

`@Transformation
class StudentTransformation(
private val logger: Logger
) :
Plugin {

override fun apply(
    builder: DynamicType.Builder<*>,
    typeDescription: TypeDescription,
    classFileLocator: ClassFileLocator
): DynamicType.Builder<*> {
    logger.lifecycle("Transforming ${typeDescription.name} with StudentTransformation")

    return builder.method(ElementMatchers.named("getFullName"))
        .intercept(MethodDelegation.to(StudentClassInterceptor::class.java))
}

override fun matches(target: TypeDescription): Boolean {
    return true
}

override fun close() {
    // Nothing to close
}

}`

and here is the interceptor
`object StudentClassInterceptor {

@JvmStatic
fun intercept(@Origin m: Method, @SuperCall originalMethodCall: Runnable): String  {
    Log.i("myTag", "Intercepted Student Class getFullName ${m.name}")
    return "John Doe"
}

}`

It is working fine when I am calling getFullName on a student object and I am getting "John Doe" as it has been intercepted.

But same thing I want to do for android View.class. Inside View class there is a method named "getHeight()" which return the height. I want to intercept this method call. When I call this method on a button I want to return a fixed value. But it is not intercepting. Here is the code for ViewTransformation

`@Transformation
class ViewTransformation(private val logger: Logger) : Plugin {

override fun apply(
    builder: DynamicType.Builder<*>,
    typeDescription: TypeDescription,
    classFileLocator: ClassFileLocator
): DynamicType.Builder<*> {
    logger.lifecycle("Transforming ${typeDescription.name} with ViewTransformation")
    return builder.method(ElementMatchers.named("getHeight"))
        .intercept(MethodDelegation.to(ViewMethodInterceptor::class.java))
}

override fun matches(target: TypeDescription): Boolean {
    return target.isAssignableTo(View::class.java)
}

override fun close() {
    // Nothing to close
}

}`

Here is the interceptor
`object ViewMethodInterceptor {

@JvmStatic
fun intercept(@Origin m: Method, @SuperCall originalMethodCall: Runnable): Int  {
    Log.i("myTag", "Intercepted View Class getHeight")
    return 500;
}

}`

Now I am calling getHeight() inside onCreate of MainActivity likhe this
btn.getHeight()

But getHeight is not intercepting. What's I am doing wrong? @LikeTheSalad

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.