Comments (39)
This issue has been fixed and will be rolled out in one of the next Android Studio 4.0 canary releases.
from app-bundle-samples.
We're currently in the progress of testing a fix for this issue.
from app-bundle-samples.
It would be nice to get a complete explanation of why this issue occurs. Android Studio can run the DFM tests without issue, and it seems to be manually passing the classpaths as CLI arguments. While refactoring code into a separate library module might fix it, in some cases this is a non-trivial task. We should not need to refactor significant amounts of our codebase just to be able to duplicate IDE functionality in a CI environment.
cc @jeffchang5
from app-bundle-samples.
The code under test needs to be accessible from the dynamic feature module's (DFM) test classes.
To enable this it either has to be in the DFM or included using androidTest(Implementation|Api)
. A way to keep it reusable throughout and not hard wire it to the DFM is to create a com.android.library
module and depend on that.
from app-bundle-samples.
I am still seeing this error
Caused by: java.lang.ClassNotFoundException:
on AS 4.2 Canary 4It has to be resolved at Canary 6.
I tried the Android Studio 4.2 Canary 7 as well, still doesn't work.
from app-bundle-samples.
Adding the line below to the dynamic feature module gradle file solved the issue on AS 4.1.1 (STABLE) Anyone knows whether the issue has been solved on any AS canary builds?
testRuntimeOnly(files("$projectDir/../app/build/intermediates/app_classes/<buildVariant>/classes.jar"))
from app-bundle-samples.
Hi Mr Wang,
App Module classes, not found from other dynamic feature module (auth in my case), when run:
./gradlew auth:test:
I did the same gradle settings as the App module, but that doesn't work for me.
Team another solution?.
from app-bundle-samples.
@MagsMagnoli
I think it helps you
// This "test" source set is a fix for SafeArgs classes not being available when running Unit tests from cmd
// See: https://issuetracker.google.com/issues/139242292
sourceSets {
getByName("test").java.srcDir("${project.rootDir}/app/build/generated/source/navigation-args/debug")
}
from app-bundle-samples.
I have the same issue on AS 4.0 even using this configuration:
testRuntimeOnly(files("$projectDir$"/../app/build/intermediates/app_classes/debug/classes.jar"))
I have tried AS 4.1 Canary 10 and I have checked it works.
Is there any way to make it work on AS 4.0?My fault! I have missed to add another dynamic feature with the
testRuntimeOnly
way. So, I have something like this:
testRuntimeOnly(files("$projectDir$"/../app/build/intermediates/app_classes/debug/classes.jar"))
testRuntimeOnly(files("$projectDir$"/../<dynamicFeatureName>/build/intermediates/app_classes/debug/classes.jar"))
For those still want to use 4.0
to supports product flavours
Modify the code into
testRuntimeOnly(files("$projectDir$"/../<baseApp>/build/intermediates/app_classes/<buildVariant>/classes.jar"))
testRuntimeOnly(files("$projectDir$"/../<dynamicFeatureName>/build/intermediates/app_classes/<buildVariant>/classes.jar")
Also make sure for /../
to have a correct path.
E.g with below directory structures:
|baseApp
|features
|--------/dynamicFeatureName
// needs to `cd` change directory twice to parent
testRuntimeOnly(files("$projectDir$"/../../<baseApp>/build/intermediates/app_classes/<buildVariant>/classes.jar"))
testRuntimeOnly(files("$projectDir$"/../../<dynamicFeatureName>/build/intermediates/app_classes/<buildVariant>/classes.jar")
from app-bundle-samples.
Not working for me even in Android Studio 4.2 Canary 7..
Also tried on AS 4.0.1 by adding the below line, but no luck
testRuntimeOnly(files("$projectDir/../app/build/intermediates/app_classes/internalDebug/classes.jar"))
testRuntimeOnly(files("$projectDir/..//build/intermediates/app_classes/internalDebug/classes.jar"))
The error is same: Unresolved reference: BaseTest (Trying to refer BaseTest present in app inside the dfm's tests)
Please help here
from app-bundle-samples.
I have the same problem and I also haven't found the solution.
from app-bundle-samples.
I'm facing the same issue as well. In my case code is in a common module shared by app and feature modules.
Full message is:
com.kouzoh.mercari.... > initializationError FAILED
java.lang.NoClassDefFoundError
Caused by: java.lang.ClassNotFoundException
Junit report:
java.lang.NoClassDefFoundError: Lcom/kouzoh/mercari/...;
at java.lang.Class.getDeclaredFields0(Native Method)
at java.lang.Class.privateGetDeclaredFields(Class.java:2583)
at java.lang.Class.getDeclaredFields(Class.java:1916)
at org.junit.runners.model.TestClass.getSortedDeclaredFields(TestClass.java:77)
at org.junit.runners.model.TestClass.scanAnnotatedMembers(TestClass.java:70)
at org.junit.runners.model.TestClass.<init>(TestClass.java:57)
at org.junit.runners.ParentRunner.createTestClass(ParentRunner.java:88)
at org.junit.runners.ParentRunner.<init>(ParentRunner.java:83)
at org.junit.runners.BlockJUnit4ClassRunner.<init>(BlockJUnit4ClassRunner.java:65)
at org.junit.internal.builders.JUnit4Builder.runnerForClass(JUnit4Builder.java:10)
...
Caused by: java.lang.ClassNotFoundException: com.kouzoh.mercari...
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
from app-bundle-samples.
I have the same issue, no solution yet.
from app-bundle-samples.
Interesting,making a project that Google wont accept. I had not expected that anyway and i thougth that is possible to make something without going to Google.
from app-bundle-samples.
Upgrading to com.android.tools.build:gradle:3.5.0 causes instrumentation tests in my dynamic feature modules to crash. Reverting back to 3.4.2 is the only solution I can find at the moment. Is this a known issue?
from app-bundle-samples.
Anyone has the solution for this issue?
from app-bundle-samples.
I have the same issue, no solution yet.
Any solution? please?
from app-bundle-samples.
@luisansal I currently do such things:
- make sure the DFMs have the same Gradle setting as the App module.
- make sure the DFMs can access the classes of the App Module.
Then it works when I run the Gradle CLI
Another thought is:
Maybe we can create interfaces in the App Module and implement these interfaces in DFMs, but that depends on how your project structures.
from app-bundle-samples.
@wangchauyan Can you please, share a part of your gradle code config, or ./gradlew command line?
from app-bundle-samples.
@luisansal
Hi,
Sorry, I can't share the code snap for you because it's internal codebase.
Here are my understanding of your situation and possible solutions,
I think your situation is that you have some classes in the App module.
And your DFM (let's say auth
) use these classes from the App module.
You can write the test cases in auth
module and import these classes from the App module.
But, when running the test case in auth
module, you might sometimes encounter a few issues.
- Can't resolve the supertype of the class in the App module
-> This means you might need to have the same Gradle implementation in yourauth
module cause the App module depends on some libraries. - NoClassDefFoundError
-> This means you might need to separate these shared classes out from the App module to a shared module for example, and you might need to create a jar file for yourauth
module or you can try something like this :
testImplementation project(path: ':App', configuration: 'tests')
in your auth
module.
Hope this helps.
from app-bundle-samples.
@masterjefferson Can you please let me know which versions of Android Studio & build tools you're using for this?
from app-bundle-samples.
@keyboardsurfer
I have tried both AS 3.5.3 and 3.6.0 RC 1 (with respective gradle plugin versions)
Build tools is 29.0.2, but also occurs with 28.0.3.
Gradle wrapper is using version 5.6.4.
from app-bundle-samples.
Same issue for me. Feature module tests fail with NoClassDefFoundError
when running them in terminal on local machine or in CI. Tests pass in Android Studio.
I'm using AS 3.5.3, build tools 29.0.2, Gradle 5.6.4
from app-bundle-samples.
@keyboardsurfer is this hot-patchable to 3.6? we are having to disable tests in feature modules because of this.
from app-bundle-samples.
Hi @chrisjenx! Unfortunately this can't be easily patched as there were major changes. Thus the version code change from 3.x to 4.x.
Your best call is to upgrade to 4.x once you're ready for it or have two versions run in parallel.
from app-bundle-samples.
@keyboardsurfer I just updated my project to Android Studio 4 and 4.0.0-beta01
gradle plugin and am still seeing NoClassDefFoundError
s related to FragmentDirections
- the generated NavDirections
for my fragment which is located in a dynamic feature module
I only see this error when executing tests via the command line
from app-bundle-samples.
It should be okay from beta02. I am on 4.1 Canary 2 and things work well here.
from app-bundle-samples.
There was another regression in the canaries. It has been resolved and should be shipped with Canary 6.
from app-bundle-samples.
i am currently dealing with this problem, nothing is working out
from app-bundle-samples.
@thapelo96 Can you confirm that the issue is reproducible when running ./gradlew connectedAndroidTest --no-parallel
using the sample code?
from app-bundle-samples.
I have the same issue on AS 4.0 even using this configuration:
testRuntimeOnly(files("$projectDir$"/../app/build/intermediates/app_classes/debug/classes.jar"))
I have tried AS 4.1 Canary 10 and I have checked it works.
Is there any way to make it work on AS 4.0?
from app-bundle-samples.
I have the same issue on AS 4.0 even using this configuration:
testRuntimeOnly(files("$projectDir$"/../app/build/intermediates/app_classes/debug/classes.jar"))
I have tried AS 4.1 Canary 10 and I have checked it works.
Is there any way to make it work on AS 4.0?
My fault! I have missed to add another dynamic feature with the testRuntimeOnly
way. So, I have something like this:
testRuntimeOnly(files("$projectDir$"/../app/build/intermediates/app_classes/debug/classes.jar"))
testRuntimeOnly(files("$projectDir$"/../<dynamicFeatureName>/build/intermediates/app_classes/debug/classes.jar"))
from app-bundle-samples.
I am still seeing this error Caused by: java.lang.ClassNotFoundException:
on AS 4.2 Canary 4
from app-bundle-samples.
I am still seeing this error
Caused by: java.lang.ClassNotFoundException:
on AS 4.2 Canary 4
It has to be resolved at Canary 6.
from app-bundle-samples.
Not working for me even in Android Studio 4.2 Canary 7..
Also tried on AS 4.0.1 by adding the below line, but no luck
testRuntimeOnly(files("$projectDir/../app/build/intermediates/app_classes/internalDebug/classes.jar"))
testRuntimeOnly(files("$projectDir/..//build/intermediates/app_classes/internalDebug/classes.jar"))The error is same: Unresolved reference: BaseTest (Trying to refer BaseTest present in app inside the dfm's tests)
Please help here
You can't refer to test classes in another modules tests - that's not related to this issue. (I'm guessing your BaseTest is in app/src/tests
and your accessing it via dfm/src/tests
?)
from app-bundle-samples.
@keyboardsurfer is there a new issue for this? As it shouldn't really be closed?
from app-bundle-samples.
FYI for all of those struggling with this workaround:
For library classes the path is different
testRuntimeOnly(files("${projectDir}/../../<library module path>/build/intermediates/compile_library_classes_jar/< buildVariant >/classes.jar"))
from app-bundle-samples.
I do not see this issue affecting the sample at hand.
Executing both ./gradlew test
or ./gradlew connectedAndroidTest
from within the DynamicFeatures
project does not yield any failed tests.
In order to see what the actual issue is, I would have to see it either being reproducible in one of the samples in this repository or with a MCVE.
from app-bundle-samples.
:alhamdulillah: upgrading to AGP 7.2, running test in DFM works without the above workaround somehow. (no testRuntimeOnly
in DFM)
from app-bundle-samples.
Related Issues (20)
- Resource Not Found error after close and relaunch the app HOT 1
- Duplicate class in play.core On Build Unity 2020 LTS
- AAssetManager cannot handle a pack nearly 2GB on 32 bit device
- Resource Not Found Exception
- Q: Instant Apps
- dynamic-feature mlkit translate
- Resource Not Found Relaunch Application on-Demand Dynamic Feature Module HOT 4
- Resources$NotFoundException HOT 4
- Sample code at app-bundle-samples/PlayAssetDelivery/NativeSample/ not generating all standalone apks HOT 1
- Play Asset Delivery Error Code does not match HOT 1
- Can PAD deliver SO?
- Security Policy violation Binary Artifacts HOT 28
- I want put all arr files to dynamic feature module, but have question
- Question: Would the install-time delivery still violate the maximum size limitation?
- GoogleAnalytics sample app build fails with "Unable to make protected void java.net.URLClassLoader.addURL(java.net.URL) accessible"
- ContentProvider in dynamic module HOT 1
- What about the assets file in the aar package?
- Dynamic feature UnsatisfiedLinkError
- Error receiving broadcast Intent
- How to customise downloading UI for on demand instant modules
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from app-bundle-samples.