Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

java.lang.NoSuchMethodException: setActivityController #66

Closed
suntzu93 opened this issue Jun 19, 2017 · 16 comments
Closed

java.lang.NoSuchMethodException: setActivityController #66

suntzu93 opened this issue Jun 19, 2017 · 16 comments

Comments

@suntzu93
Copy link

Hi All,
I have issue when run code . My error :
Failed to install custom IActivityController: setActivityController [interface android.app.IActivityController]
java.lang.NoSuchMethodException: setActivityController [interface android.app.IActivityController]
at java.lang.Class.getMethod(Class.java:1981)
at java.lang.Class.getDeclaredMethod(Class.java:1960)

error at method :
private static void setActivityController(@nullable IActivityController activityController) {
try {
Class<?> amClass = Class.forName("android.app.ActivityManagerNative");
Method getDefault = amClass.getMethod("getDefault");
Object am = getDefault.invoke(null);
Log.d(TAG, "setActivityController: " + am.getClass());
Method setMethod = am.getClass().getDeclaredMethod("setActivityController", new Class[]{IActivityController.class});
setMethod.invoke(am, activityController);
} catch (Throwable e) {
Log.e(TAG, "Failed to install custom IActivityController: " + e.getMessage(), e);
}
}

Can you tell me how to fix this error ?

@drewhannay
Copy link
Contributor

Can you share more info about your setup? What kind of emulator are you using? And what version of Test Butler?

@Kisty
Copy link
Contributor

Kisty commented Jun 19, 2017

I've seen this before. You aren't using Gradle 3.5 are you? If so, try Gradle 3.4.1.

You can find out the version by looking at gradle/wrapper/gradle-wrapper.properties file and check the distributionUrl

@drewhannay
Copy link
Contributor

I'd be curious to know how Gradle version could cause this. We've used Test Butler with Gradle 3.5 as well as Gradle 4.0 without any issues.

@Kisty
Copy link
Contributor

Kisty commented Jun 19, 2017

Ignore that last suggestion, sorry.

Sounds like a mismatch of test butler versions on the emulator and the library version used in androidTest.

  1. Download and install the latest test butler APK from here (currently 1.3.1) on the emulator.
  2. Check the test butler library is the same version as used in the code.
    e.g.
    androidTestCompile 'com.linkedin.testbutler:test-butler-library:1.3.1'

@suntzu93
Copy link
Author

suntzu93 commented Jun 20, 2017

I'm using nexus 5x . I tried run on emulator nexus 6p then it's ok. I don't know why.
I think that with API 25 android has changed parameter of method setActivityController so I can't call this method with one parameter.
After research code and I found the method had changed :
setActivityController(android.app.IActivityController,boolean) .
and I fixed as :
Method updateConfiguration = am.getClass().getMethod("setActivityController", IActivityController.class, boolean.class);
It's ok on API 25

@Kisty
Copy link
Contributor

Kisty commented Jun 20, 2017

I've been able to use it fine on a Nexus 5X API 25 emulator fine. Not sure what's different. What api level was the Nexus 5X and Nexus 6P at? Were they different?

@suntzu93
Copy link
Author

suntzu93 commented Jun 20, 2017

I don't know but when I run on nexus 5x with API 25 then I have to fix code with two params. I run on simulator 6P API 23 then I don't have to fix code.

@Kisty
Copy link
Contributor

Kisty commented Jun 20, 2017

Quick question: Do the emulators come with Google APIs (e.g. Google maps, etc)?

@suntzu93
Copy link
Author

yeah, it has Google APIs

@Kisty
Copy link
Contributor

Kisty commented Jun 20, 2017

OK, try using an emulator image API 25 without Google APIs.

@suntzu93
Copy link
Author

I tried run with API 25 without Google APIs and it's ok. Don't need to fix code .

@Kisty
Copy link
Contributor

Kisty commented Jun 20, 2017

Cool. But I am running tests on API 25 with Google APIs on my machine. It's bizarre why it's not working on your machine.

Does it manage to do some tests and then fails on one test or does the build fail setting up tests?

@saildeep
Copy link

saildeep commented Aug 9, 2017

Is there a workaround without compiling test butler myself? Are there any other google api emulators i could use?

@Gavinpub
Copy link

Can your demo invoke setActivityController successfully ? As I know system will check if the caller has permission <android.permission.SET_ACTIVITY_WATCHER>. If no, it will fail to invoke. Unfortunately the permission is HIDE and system app use only. Is it possilbe to invoke it on 3rd party app?

@ewolfe123
Copy link
Contributor

ewolfe123 commented Mar 15, 2018

I see the same issue using Test Butler 1.3.1, Pixel Emulator, API 25 w/ Google APIs. I've verified that the apk and library versions match. I don't see a system image in sdkmanager for API 25 without Google APIs.

This issue occurs both on setup and teardown. Stack trace:

03-15 18:26:31.624 10149-10149/? D/ButlerService: ButlerService starting up...
03-15 18:26:31.639 10149-10149/? E/NoDialogActivityController: Failed to install custom IActivityController: setActivityController [interface android.app.IActivityController]
                                                               java.lang.NoSuchMethodException: setActivityController [interface android.app.IActivityController]
                                                                   at java.lang.Class.getMethod(Class.java:1981)
                                                                   at java.lang.Class.getMethod(Class.java:1637)
                                                                   at com.linkedin.android.testbutler.NoDialogActivityController.setActivityController(NoDialogActivityController.java:114)
                                                                   at com.linkedin.android.testbutler.NoDialogActivityController.install(NoDialogActivityController.java:95)
                                                                   at com.linkedin.android.testbutler.ButlerService.onCreate(ButlerService.java:147)

I am also unable to install the test butler APK on API 24 or 26.
Has there been any progress on this issue? I had to make the same code change as @thanhlv93, and pass an Object params array to setMethod.invoke().

@Kisty which revision of the API 25 Google APIs system image are you using? I am using the latest, which is 11

@drewhannay
Copy link
Contributor

The fix for this has been merged, I'll do a new release sometime this week.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants