Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Instrumented Tests Will Not Run -- 6 files found with path 'META-INF/LICENSE.md'

Edit: Found out that MockK is causing this issue. I guess it is duplicating these files when I'm mocking my API request. When I remove MockK and/or Mockito. I do not get these errors. Any ideas?

Getting this error stating that there are these duplicate meta data files. I tried adding the packagingOptions block in my build.gradle file to exclude these files, but then my tests won't run at all. Is there a way to manually remove the duplicates? Where would these files be located? Any help is greatly appreciated. I am lost lol.

Tests:

    @RunWith(AndroidJUnit4::class)
    class ViewModelTests {
    
        @get:Rule(order = 1)
        val testRule = ActivityScenarioRule(MainActivity::class.java)
    
        private lateinit var viewModel: NewsViewModel
        private lateinit var repositoryImpl: RepositoryImpl
        private val context = InstrumentationRegistry.getInstrumentation().targetContext
    
        @Before
        fun setUp() {
            val newsDao = NewsDatabase.getDatabase(context).myDao()
            val newsApi = mockk<NewsApi>()
            viewModel = mockk()
            repositoryImpl = RepositoryImpl(newsApi, newsDao)
        }
    
        @Test
        fun test_empty_database() = runBlocking {
            assertEquals(0, repositoryImpl.getNewsFromDatabase.value?.size)
        }
    }

Error: Execution failed for task ':app:mergeDebugAndroidTestJavaResource'.

A failure occurred while executing com.android.build.gradle.internal.tasks.MergeJavaResWorkAction 6 files found with path 'META-INF/LICENSE.md' from inputs: - /Users/sammorton/.gradle/caches/modules-2/files-2.1/org.junit.jupiter/junit-jupiter-params/5.8.2/ddeafe92fc263f895bfb73ffeca7fd56e23c2cce/junit-jupiter-params-5.8.2.jar - /Users/sammorton/.gradle/caches/modules-2/files-2.1/org.junit.jupiter/junit-jupiter-engine/5.8.2/c598b4328d2f397194d11df3b1648d68d7d990e3/junit-jupiter-engine-5.8.2.jar - /Users/sammorton/.gradle/caches/modules-2/files-2.1/org.junit.jupiter/junit-jupiter-api/5.8.2/4c21029217adf07e4c0d0c5e192b6bf610c94bdc/junit-jupiter-api-5.8.2.jar - /Users/sammorton/.gradle/caches/modules-2/files-2.1/org.junit.platform/junit-platform-engine/1.8.2/b737de09f19864bd136805c84df7999a142fec29/junit-platform-engine-1.8.2.jar - /Users/sammorton/.gradle/caches/modules-2/files-2.1/org.junit.platform/junit-platform-commons/1.8.2/32c8b8617c1342376fd5af2053da6410d8866861/junit-platform-commons-1.8.2.jar - /Users/sammorton/.gradle/caches/modules-2/files-2.1/org.junit.jupiter/junit-jupiter/5.8.2/5a817b1e63f1217e5c586090c45e681281f097ad/junit-jupiter-5.8.2.jar Adding a packagingOptions block may help, please refer to https://developer.android.com/reference/tools/gradle-api/7.3/com/android/build/api/dsl/ResourcesPackagingOptions for more information

like image 672
sam_1234 Avatar asked Sep 02 '25 05:09

sam_1234


1 Answers

You can choose among the ResourcePackingOptions pickFirsts, merges, and excludes. Depending on the licenses, you might not be allowed to exclude them.

https://developer.android.com/reference/tools/gradle-api/8.0/com/android/build/api/dsl/ResourcesPackagingOptions

Android Studio projects default exclude licenses that don't require it (AL2 and LGPL2). For the rest, merging them together is a reasonable approach -

packagingOptions {
    resources {
        excludes += "/META-INF/{AL2.0,LGPL2.1}"
        merges += "META-INF/LICENSE.md"
        merges += "META-INF/LICENSE-notice.md"
    }
}
like image 186
Offbeat Upbeat Avatar answered Sep 04 '25 20:09

Offbeat Upbeat



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!