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
Can't load assets after updating to gradle 2.2.0 #2647
Comments
In case it helps: I am experiencing the same issue but only with the debug variant (release variant is still working fine). |
@andymstone Thank you for the work around. I rolled back to 2.1.3 and went back to 100% passed. |
Ditto. Tests work as expected with AS 2.2 and tools 2.1.3. |
May be related to #2581 |
what does you @config look like? |
I got the same problem |
It looks like gradle plugin 2.2.0 no longer copies assets into My fix would be to allow fallback to
If you use |
I deleted my previous comment about assets working correctly with android gradle plugin 2.2.0 and Gradle 3.1, because it still did not work in some environments. However, after exiting Android Studio, stopping the gradle daemon ( |
Adding the following to
This creates a dependency for all |
@otbinary thx it works. Just had to edit for projects with no product flavors
|
I used the workaround from @Vouskopes (which worked great!), but was able to successfully remove it after updating to Gradle 2.2.1, which was just released yesterday. Upgrade to com.android.tools.build:gradle:2.2.1 and this issue could probably be closed. |
@bojingo Unfortunately I can't confirmed that it's fixed. I've tried the Gradle plugin 2.2.1 with both Android Studio 2.2 and 2.2.1, performed full clean each time (including Gradle cache removal) and I've had my Robolectric fail because of the missing assets. @Vouskopes's fix is still required for me! |
Works for me with Gradle 2.2.1 ! 👍 |
@bojingo @Teka101 Make sure to do the clean before.
You'll notice 2.2.1 does not fix anything. You probably simply had run generate before which has a dependency on generateAssets task whereas test does not anymore (you can take a look at task dependencies running |
Oups.... you're rights ! 2.2.1 doesn't fix the bug... |
After updating to gradle 2.2.0 the app/build/intermediates directory no longer contains an assets directory (the app still builds and runs correctly so this appears to be a change in how the build process works). This means that Robolectric tests that rely on loading any assets will fail. robolectric/robolectric#2647
With |
I don't think it will be fixed on Google side. They changed their internal implementations, so we should adapt Robolectric functionality. |
Hey @Vouskopes ,i get same issue . But in my case , i meet this issue in a library project and assert files needed are in another aar library which this library have to be dependent on . i've tried adding applicationVariants.all { variant ->
def productFlavor = variant.productFlavors[0] != null ? "${variant.productFlavors[0].name.capitalize()}" : ""
def buildType = "${variant.buildType.name.capitalize()}"
tasks["compile${productFlavor}${buildType}UnitTestSources"].dependsOn(tasks["merge${productFlavor}${buildType}Assets"])
} in |
Fixed on master with #2673. Thanks all! |
I don't see anything about this having been released. Any idea on when this will be available in the central repositories so we can take advantage of this fix? |
I'm still having the same issue. Tried to use the latest stable version 3.1.4 and robolectric:3.2-SNAPSHOT. |
@storix it is fixed on 3.1.4, you must be referring to a different problem |
This is definitely not fixed with 3.1.4. My custom font (.ttf) file in the asset folder is not found when running Robolectric tests unless I have the fix from @Vouskopes. Should be re-opened if 3.1.4 was expected to fix it. |
@bojingo 3.1.4 was released before the 2673 issue was merged therefore it is certainly not in this one but should although be in 3.2 that was juste released this week I think! :) |
Yep, this is fixed with 3.2. |
@xian I am using Robolectric 3.2.2, Android Gradle Plugin 2.2.3 and AS 2.2.3 and I still have the issue. The only way to have it working is using the workaround by @otbinary. The weird thing is that locally works fine, but when running on a CI server it fails. Any ideas? Any directions to point me on what to check on the CI server setup? |
I am seeing this issue in 3.3 version as well |
still experiencing the same with 3.2.2 and gradle 2.3.0. The workaround created by @otbinary works meanwhile |
If your build file contains the cross-product combination between flavor dimension and product flavor, this worked for me: applicationVariants.all {variant ->
def flavorName = variant.flavorName.capitalize()
def buildType = variant.buildType.name.capitalize()
tasks["compile${flavorName}${buildType}UnitTestSources"]
.dependsOn(tasks["merge${flavorName}${buildType}Assets"])
} |
This is caused by an issue with the Android Gradle plugin, tracked here: https://issuetracker.google.com/issues/37347564 Will keep this open until it's resolved there. |
see robolectric/robolectric#2647 and https://issuetracker.google.com/issues/37347564 A temporary workaround is to add task dependency on merge*Assets
Note: assets error ("Font not found at") occurs due to a gradle bug see robolectric/robolectric#2647 and https://issuetracker.google.com/issues/37347564
@nico-gonzalez for some reason the gradle task:
is not always called (and this one depends on task merge$ProductFlavor$BuildTypeAssets) The ugly fix could be done by calling manualy this task before running tests:
of course this solution works only together with this snippet in build.gradle:
|
This variant of the workaround also works for multiple flavor dimensions:
|
Shouldn't it be closed? Corresponded ticked is fixed (https://issuetracker.google.com/issues/37347564) |
We had an issue after upgrading Gradle version to
|
GradleRobolectricTestRunner has been removed, instead you can simply use RobolectricTestRunner. You also no longer need to specify @config(constants = ..., manifest = ...) We've revamped resources in Robolectric 4.0 to process the binary resource files + arsc table produced by aapt and the resource handling code is now much closer to that of the framework. This includes changes to parse the merged manifest using the Android platform code. Mind giving this a try with 4.0 + binary resources by configuring your gradle.build as follows:- testImplementation "org.robolectric:robolectric:4.0"
android {
enableUnitTestBinaryResources=true
testOptions {
unitTests {
includeAndroidResources = true
}
}
} We're doing a big bug scrub and trying to be aggressive about it so apologies if this was closed in error, in which case feel free to reopen. If this is still an issue an example project with failing test would be most helpful. |
Description
After updating to gradle 2.2.0 the
app/build/intermediates
directory no longer contains anassets
directory (the app still builds and runs correctly so this appears to be a change in how the build process works). This means that Robolectric tests that rely on loading any assets will fail.Steps to Reproduce
Put a file in
app/src/main/assets
then try to open the file, e.g.This works using gradle 2.1.3 and fails with gradle 2.2.0.
Robolectric & Android Version
Robolectric 3.1.2, Android 23
The text was updated successfully, but these errors were encountered: