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.NoClassDefFoundError: Failed resolution of: Ljava/beans/Introspector; #1062

Open
sevenfirezzz opened this issue Jul 30, 2020 · 2 comments · May be fixed by #1067
Open

java.lang.NoClassDefFoundError: Failed resolution of: Ljava/beans/Introspector; #1062

sevenfirezzz opened this issue Jul 30, 2020 · 2 comments · May be fixed by #1067

Comments

@sevenfirezzz
Copy link

sevenfirezzz commented Jul 30, 2020

I am using Powermock:
`
// androidx
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.0'
androidTestImplementation 'androidx.test.ext:junit:1.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'

// power mock
androidTestImplementation group: 'org.powermock', name: 'powermock-module-junit4', version: '2.0.0'
androidTestImplementation group: 'org.powermock', name: 'powermock-api-mockito2', version: '2.0.0'

`

When I run test like this, it can be run success.
`
@RunWith(AndroidJUnit4.class)
public class UtilTest {

@Test
public void testUtil(){
    String test = HomeCountryUtil.genCountry();
    assert test != null;
}

}
`

But when I replace RunWith by PowerMock,it run failed.
`
@RunWith(PowerMockRunner.class)
public class UtilTest {

@Test
public void testUtil(){
    String test = HomeCountryUtil.genCountry();
    assert test != null;
}

}
`

The exception log :
E/TestRunner: failed: initializationError(com.lyhexample.firstapp.mock.UtilTest) ----- begin exception ----- E/TestRunner: java.lang.NoClassDefFoundError: Failed resolution of: Ljava/beans/Introspector; at org.powermock.configuration.support.ConfigurationMapper.map(ConfigurationMapper.java:44) at org.powermock.configuration.support.ConfigurationBuilder$ConfigurationCreator.mapConfiguration(ConfigurationBuilder.java:80) at org.powermock.configuration.support.ConfigurationBuilder$ConfigurationCreator.create(ConfigurationBuilder.java:69) at org.powermock.configuration.support.ConfigurationBuilder.fromProperties(ConfigurationBuilder.java:54) at org.powermock.configuration.support.ConfigurationFactoryImpl.readEnvironmentConfiguration(ConfigurationFactoryImpl.java:62) at org.powermock.configuration.support.ConfigurationFactoryImpl.create(ConfigurationFactoryImpl.java:52) at org.powermock.configuration.GlobalConfiguration.createConfig(GlobalConfiguration.java:75) at org.powermock.configuration.GlobalConfiguration.<init>(GlobalConfiguration.java:59) at org.powermock.configuration.GlobalConfiguration.powerMockConfiguration(GlobalConfiguration.java:44) at org.powermock.core.classloader.ByteCodeFramework.getByteCodeFrameworkForTestClass(ByteCodeFramework.java:49) at org.powermock.core.transformers.TestClassTransformerBuilder.removesTestMethodAnnotation(TestClassTransformerBuilder.java:25) at org.powermock.tests.utils.impl.AbstractCommonTestSuiteChunkerImpl.createDefaultMockLoader(AbstractCommonTestSuiteChunkerImpl.java:125) at org.powermock.tests.utils.impl.AbstractCommonTestSuiteChunkerImpl.chunkClass(AbstractCommonTestSuiteChunkerImpl.java:89) at org.powermock.tests.utils.impl.AbstractCommonTestSuiteChunkerImpl.<init>(AbstractCommonTestSuiteChunkerImpl.java:50) at org.powermock.tests.utils.impl.AbstractCommonTestSuiteChunkerImpl.<init>(AbstractCommonTestSuiteChunkerImpl.java:44) at org.powermock.tests.utils.impl.AbstractTestSuiteChunkerImpl.<init>(AbstractTestSuiteChunkerImpl.java:57) at org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.<init>(JUnit4TestSuiteChunkerImpl.java:57) at org.powermock.modules.junit4.common.internal.impl.AbstractCommonPowerMockRunner.<init>(AbstractCommonPowerMockRunner.java:36) at org.powermock.modules.junit4.PowerMockRunner.<init>(PowerMockRunner.java:34) at java.lang.reflect.Constructor.newInstance0(Native Method) at java.lang.reflect.Constructor.newInstance(Constructor.java:343) at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:104) at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:86) at androidx.test.internal.runner.junit4.AndroidAnnotatedBuilder.runnerForClass(AndroidAnnotatedBuilder.java:63) at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59) at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26) at androidx.test.internal.runner.AndroidRunnerBuilder.runnerForClass(AndroidRunnerBuilder.java:153) at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59) at androidx.test.internal.runner.TestLoader.doCreateRunner(TestLoader.java:73) at androidx.test.internal.runner.TestLoader.getRunnersFor(TestLoader.java:104) at androidx.test.internal.runner.TestRequestBuilder.build(TestRequestBuilder.java:789) at androidx.test.runner.AndroidJUnitRunner.buildRequest(AndroidJUnitRunner.java:543) at androidx.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:386) at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:2251) Caused by: java.lang.ClassNotFoundException: Didn't find class "java.beans.Introspector" on path: DexPathList[[zip file "/data/app/com.lyhexample.firstapp.test-78UV7bYZZe9yyKyM8szOOA==/base.apk", zip file "/data/app/com.lyhexample.firstapp-Mm7510nQw6GUeYxDzZ8MNA==/base.apk"],nativeLibraryDirectories=[/data/app/com.lyhexample.firstapp.test-78UV7bYZZe9yyKyM8szOOA==/lib/arm64, /data/app/com.lyhexample.firstapp-Mm7510nQw6GUeYxDzZ8MNA==/lib/arm64, /system/lib64, /system/product/lib64, /hw_product/lib64, /sys ----- end exception ----- I/TestRunner: finished: initializationError(com.lyhexample.firstapp.mock.UtilTest) I/xample.firstap: jit_compiled:[OK] java.lang.Object java.lang.ref.Reference.get() @ /apex/com.android.runtime/javalib/core-oj.jar I/MonitoringInstr: Activities that are still in CREATED to STOPPED: 0 I/TestRunner: run finished: 1 tests, 1 failed, 0 ignored

@sevenfirezzz
Copy link
Author

sevenfirezzz commented Jul 30, 2020

The keywords of error:
Caused by: java.lang.ClassNotFoundException: Didn't find class "java.beans.Introspector" on path ----- end exception -----

allenluce pushed a commit to allenluce/powermock that referenced this issue Sep 1, 2020
The Android implementation of java.beans does not include everything
which gives rise to error messages like this:

    E/TestRunner: java.lang.NoClassDefFoundError: Failed resolution of: Ljava/beans/Introspector; at
       org.powermock.configuration.support.ConfigurationMapper.map(ConfigurationMapper.java:44) at
       org.powermock.configuration.support.ConfigurationBuilder$ConfigurationCreator.mapConfiguration(ConfigurationBuilder.java:80) at
       ...

While it's not clear to me why such abject fanciness is needed in the
ConfigurationMapper to take care of a sum total of three properties,
it is clear that this change represents a minimum of source changes to
get to a working state.

Fixes powermock#1062
@allenluce
Copy link

The problem here is that Google didn't implement the full Java Beans system on Android. There are a few different ways around it, I've submitted a PR with a fairly straightforward drop-in replacement for Java Beans.

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

Successfully merging a pull request may close this issue.

2 participants