I'm stuck listing transitive closure of runtime dependencies in Gradle Android project. Trying to do it like this:
task listDependencies {
doLast {
def configuration = project.configurations.debugRuntimeClasspath
for (file in configuration.files) {
println(file)
}
}
}
However, this produces following error:
Execution failed for task ':***:listDependencies'.
> Could not resolve all files for configuration ':***:debugRuntimeClasspath'.
> The consumer was configured to find a runtime of a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'debug'. However we cannot choose between the following variants of project :***:
- Configuration ':***:debugRuntimeElements' variant android-aar-metadata declares a runtime of a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'debug':
- Unmatched attributes:
- Provides attribute 'artifactType' with value 'android-aar-metadata' but the consumer didn't ask for it
- Provides attribute 'com.android.build.api.attributes.VariantAttr' with value 'debug' but the consumer didn't ask for it
- Configuration ':***:debugRuntimeElements' variant android-assets declares a runtime of a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'debug':
- Unmatched attributes:
- Provides attribute 'artifactType' with value 'android-assets' but the consumer didn't ask for it
- Provides attribute 'com.android.build.api.attributes.VariantAttr' with value 'debug' but the consumer didn't ask for it
- Configuration ':***:debugRuntimeElements' variant android-classes-directory declares a runtime of a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'debug':
Related
I am trying to build a react native app in a github action using the following config file and I am getting the following error. Any idea how to fix this?
name: "Android Build"
on:
workflow_call:
inputs:
environment:
required: true
type: string
publish:
required: false
type: boolean
description: Publish to Appcenter
# secrets:
# NPM_TOKEN:
# required: true
# APP_CENTER_TOKEN_ANDROID:
# required: true
jobs:
build-android:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- name: Use Node.js 14
uses: actions/setup-node#v3
with:
node-version: 14
cache: "yarn"
- name: Install Node modules
run: |
cd app && yarn ci && cd ..
- name: Cache Gradle Wrapper
uses: actions/cache#v2
with:
path: ~/app/.gradle/wrapper
key: ${{ runner.os }}-gradle-wrapper-${{ hashFiles('gradle/wrapper/gradle-wrapper.properties') }}
- name: Cache Gradle Dependencies
uses: actions/cache#v2
with:
path: ~/app/.gradle/caches
key: ${{ runner.os }}-gradle-caches-${{ hashFiles('gradle/wrapper/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-caches-
- name: Make Gradlew Executable
run: cd app/android && chmod +x ./gradlew
# Build Command
- name: Build Android ${{inputs.environment == 'release' && 'Release' || 'Debug'}}
run: |
cd app/android && ./gradlew assemble${{inputs.environment == 'release' && 'Release' || 'Debug'}} --no-daemon
# Upload to Artifact
- name: Upload Artifact
uses: actions/upload-artifact#v3
with:
name: FinderUK.aab
path: "android/app/build/outputs/bundle/release/app-release.aab"
Currently detected usages in: root project 'finderUk', project ':amplitude_react-native', project ':app', ...
FAILURE: Build failed with an exception.
* What went wrong:
Could not determine the dependencies of task ':app:lintVitalDevelopmentRelease'.
> Could not resolve all artifacts for configuration ':app:productionProductionreleaseCompileClasspath'.
> Could not resolve project :amplitude_react-native.
Required by:
project :app
> No matching variant of project :amplitude_react-native was found. The consumer was configured to find an API of a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'productionrelease', attribute 'store' with value 'play', attribute 'default' with value 'production' but:
- Variant 'debugApiElements' capability finderUk:amplitude_react-native:unspecified declares an API of a component:
- Incompatible because this component declares a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'debug' and the consumer needed a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'productionrelease'
- Other compatible attributes:
- Doesn't say anything about default (required 'production')
- Doesn't say anything about store (required 'play')
- Variant 'debugRuntimeElements' capability finderUk:amplitude_react-native:unspecified declares a runtime of a component:
- Incompatible because this component declares a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'debug' and the consumer needed a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'productionrelease'
- Other compatible attributes:
- Doesn't say anything about default (required 'production')
- Doesn't say anything about store (required 'play')
- Variant 'releaseApiElements' capability finderUk:amplitude_react-native:unspecified declares an API of a component:
- Incompatible because this component declares a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'release' and the consumer needed a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'productionrelease'
- Other compatible attributes:
- Doesn't say anything about default (required 'production')
- Doesn't say anything about store (required 'play')
- Doesn't say anything about store (required 'play')
> Could not resolve project :react-native-vector-icons.
Required by:
project :app
> No matching variant of project :react-native-vector-icons was found. The consumer was configured to find an API of a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'productionrelease', attribute 'store' with value 'play', attribute 'default' with value 'production' but:
- Variant 'debugApiElements' capability finderUk:react-native-vector-icons:unspecified declares an API of a component:
- Incompatible because this component declares a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'debug' and the consumer needed a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'productionrelease'
- Other compatible attributes:
- Doesn't say anything about default (required 'production')
- Doesn't say anything about store (required 'play')
- Variant 'debugRuntimeElements' capability finderUk:react-native-vector-icons:unspecified declares a runtime of a component:
- Incompatible because this component declares a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'debug' and the consumer needed a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'productionrelease'
- Other compatible attributes:
- Doesn't say anything about default (required 'production')
- Doesn't say anything about store (required 'play')
- Variant 'releaseApiElements' capability finderUk:react-native-vector-icons:unspecified declares an API of a component:
- Incompatible because this component declares a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'release' and the consumer needed a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'productionrelease'
- Other compatible attributes:
- Doesn't say anything about default (required 'production')
- Doesn't say anything about store (required 'play')
- Variant 'releaseRuntimeElements' capability finderUk:react-native-vector-icons:unspecified declares a runtime of a component:
- Incompatible because this component declares a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'release' and the consumer needed a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'productionrelease'
- Other compatible attributes:
- Doesn't say anything about default (required 'production')
- Doesn't say anything about store (required 'play')
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
After updating 'com.android.tools.build:gradle' from version 4.1.3 to 4.2.0, I started to get an error that 'manifestPlaceholders' are no longer merged into the manifest when running unit tests. Everything works fine when I run the app. It just fails when running tests.
defaultConfig {
(...)
manifestPlaceholders = [
myPlaceholder1: "some_value_1",
myPlaceholder2: "some_value_2"
]
}
Any unit test in the "test" folder now fails with this message:
> Task :myLib:processDebugUnitTestManifest FAILED
/myProject/source/android/myProject/build/intermediates/tmp/manifest/test/debug/manifestMerger684952061703372993.xml Error:
Attribute attribute1 at manifestMerger684952061703372993.xml requires a placeholder substitution but no value for <myPlaceholder1> is provided.
/myProject/source/android/myProject/build/intermediates/tmp/manifest/test/debug/manifestMerger684952061703372993.xml Error:
Attribute attribute2 at manifestMerger684952061703372993.xml requires a placeholder substitution but no value for <myPlaceholder2> is provided.
I had to downgrade again to version 4.1.3. Anyone has any solution for this?
This is a specific work around here, as my issues stemmed from the required manifestPlaceHolders for the Auth0 library. I was able to work around the manifest merger issue on the unit tests build by adding a manifest to each modules unit test directory (not AndroidTest directory). The manifest I used just disabled the need for the placeholders by removing the activities that required it:
https://github.com/openid/AppAuth-Android/blob/master/library/javatests/AndroidManifest.xml
Perhaps if that manifest doesn't work for you could add the placeholders directly to the manifest in the unit test directory. I didn't try this but that might be a path forward.
Here's my main project structure:
App/src
- main
- flavor1
- flavor2
- dimension1
- dimension2
- debug
- release
Both flavor* and dimension* are flavor dimensions. The build variants are:
flavor1Dimension1Debug
flavor1Dimension2Debug
flavor2Dimension1Debug
...
And library's dir structure:
Lib/src
- main
- flavor2
- DebugInterceptor.java
- debug
- DebugInterceptor.java
- release
- DebugInterceptor.java
What I want:
if variant contains 'flavor2', this variant should use src/flavor2/DebugInterceptor.java. It should take higher priority than build types. You can assume that these three dirs(flavor2, debug, release) contain only one file DebugInterceptor.java
o.w. merging by default build rules.
How can I configure gradle to achieve this?
use only one dimension and multiple flavor, don't use multiple dimension or remove code from dimension, dimension is not suitable for code but for other configs like api level
Butterknife 8.8.0 introduced the new processor option butterknife.debuggable (link to changelog). By default, it's true. Where do I set it to false in my build.gradle file? I tried placing it in my defaultConfig, but I keep getting the error:
Could not get unknown property 'butterknife'...
Looks like Butterknife mirrors the debuggable attribute of your current config. So setting debuggable inside your defaultConfig or other build type should also set butterknife.debuggable.
EDIT: My initial answer was incorrect. Add this to your Gradle build type to modify the butterknife.debuggable flag:
javaCompileOptions.annotationProcessorOptions.arguments['butterknife.debuggable'] = 'false'
I have got the following trouble: I have installed SonarQube and Android Plugin with "Android Lint" Quality Profile. When I execute my build.gradle script with "Android Lint" profile, sonar-runner plugin works good, but in SonarQube I can see no matching issues found, just zero.
Nevertheless, when I include another profile –not "Android Lint"– I can see a lot of issues. Also in my android SDK when apply it's own lint I can see 157 issues. What it can be?
sonar - version 3.7.4;
android plugin - version 0.1
Your sonar.sources property should point to the root of AndroidManifest.xml file. E.g. if your AndroidManifest.xml file is located in src/main then your build.gradle file should contain:
sonarRunner {
sonarProperties {
...
property "sonar.sources", "src/main"
property "sonar.profile", "Android Lint"
...
}
}
If you need more paths in sonar.sources you can put them as a comma-separated list.
You can find how Sonar Android Plugin determines whether to run the analysis in its source code.
change your sonar properties like this:
apply plugin: "org.sonarqube"
sonarqube {
properties {
property "sonar.projectName", "appa"
property "sonar.projectKey", "appa_app"
property "sonar.projectVersion", "1.0"
property "sonar.analysis.mode", "publish"
property "sonar.language", "java"
property 'sonar.sourceEncoding', "UTF-8"
property "sonar.sources", "./src/main"
//property "sonar.exclusions", "**/*Entity.java"
// property "sonar.exclusions", "src/main/java/com/apparkb/model/**, **/*Entity.java"
property "sonar.host.url", "http://192.168.21.33:9000"
property "sonar.login", "admin"
property "sonar.profile", "testlint"//use your quality profile instead
property 'sonar.import_unknown_files', true
property "sonar.android.lint.report", "./build/outputs/lint-results-debug.xml"
property "sonar.password", "admin"
property "sonar.java.binaries", "build/"
}
}
For creating lint-results-debug.xml you will have to run the below command on studio terminal:
./gradlew lint
It will generate the missing XML report. Be carful, it can generate a report for each build variant (Debug by default will generate build/outputs/lint-results-debug.xml). So you can call lintDebug, lintRelease... dependings on your build variant.
And change the lint properties to:
lintOptions { // set to true to turn off analysis progress reporting by lint
quiet true
// if true, stop the gradle build if errors are found
abortOnError false
// do not ignore warnings
warningsAsErrors true
}
now if you run
./gradlew sonarqube
you will get the results shown its actually the local file report that's actually getting hosted upon the server
Unfortunately if you merely point sonar.sources to src/main, you're going to get issues with all your source because you most likely don't mave minSdkVersion and targetSdkVersion set (it comes from gradle). I've tried setting my source to be some thing like:
build/intermediates/bundles/release,src/main/java
But I still get an inordinate amount of (invalid) errors due to API levels.