I try to add the dependencyResolutionManagement block to my build.gradle file.
I use this code in my build.gradle file:
plugins {
id 'com.android.application'
}
android {
compileSdkVersion 30
buildToolsVersion "30.0.3"
defaultConfig {
applicationId "com.example.findyourtimetable"
minSdkVersion 24
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
}
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
def fragment_version = "1.5.5"
implementation "androidx.fragment:fragment:$fragment_version"
}
I have the following error :
Build file '...\app\build.gradle' line: 5
A problem occurred evaluating project ':app'.
> No signature of method: build_2qy3qm6nv25wc6g469gv6z2jt.android() is applicable for argument types: (build_2qy3qm6nv25wc6g469gv6z2jt$_run_closure1) values: [build_2qy3qm6nv25wc6g469gv6z2jt$_run_closure1#35f3e998]
* 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.
I tried to change the location of the dependencyResolutionManagement block but the function is not recognize.
I don't know what to do to solve this problem
thanks in advance for any help
You should add
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
}
}
into your settings.gradle file. You can take a look an example here from the nowinandroid app github repo.
I added the dependency org.apache.http.impl.client:client-DefaultHttpClient:4.2.6 on build.gradle for my android studio project. (Just for context, I am trying to use HttpClient to access help access data in php files). However, when I try to apply this dependency, I get an output message saying that my execution failed for the following reason:
8: Task failed with an exception.
-----------
* What went wrong:
Execution failed for task ':app:mergeDebugNativeLibs'.
> Could not resolve all files for configuration ':app:debugRuntimeClasspath'.
> Could not find org.apache.http.impl.client:client-DefaultHttpClient:4.2.5.
Searched in the following locations:
- https://dl.google.com/dl/android/maven2/org/apache/http/impl/client/client-DefaultHttpClient/4.2.5/client-DefaultHttpClient-4.2.5.pom
- https://repo.maven.apache.org/maven2/org/apache/http/impl/client/client-DefaultHttpClient/4.2.5/client-DefaultHttpClient-4.2.5.pom
Required by:
project :app
The implementation is being searched for online, but I am not sure why this is the case, since I have a .jar file
located in the cache subfolder of a .gradle folder. Does anyone know what could be causing this problem?
Build.Gradle code for reference:
plugins {
id 'com.android.application'
}
android {
compileSdk 32
defaultConfig {
applicationId "com.example.myapplication"
minSdk 21
targetSdk 32
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
useLibrary 'org.apache.http.legacy'
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'com.google.android.material:material:1.5.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
implementation 'org.apache.http.impl.client:client-DefaultHttpClient:4.2.5'
//implementation 'org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.2.6'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
add this to your app level build.gradle:
android {
useLibrary 'org.apache.http.legacy'
}
I have an app and two library modules - moduleA, moduleB.
Both of these modules are using a common jar file "xyz.jar" which is being placed in their respective libs folder.
When i am trying to build this project in Android studio i am getting following error -
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task
':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
> com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex
I have already enabled multi dex by adding following lines in build files-
multiDexEnabled true
api 'com.android.support:multidex:1.0.2'
Could anyone please help? Almost whole day have been gone without any solution.
build.gradle for ModuleA
apply plugin: 'com.android.library'
android {
compileSdkVersion 28
defaultConfig {
minSdkVersion 21
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation files('libs/bbdevice-android-3.4.1.jar')
}
build.gradle for ModuleB
apply plugin: 'com.android.library'
android {
compileSdkVersion 28
defaultConfig {
minSdkVersion 21
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:28.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation files('libs/bbdevice-android-3.4.7.jar')
implementation files('libs/bbdeviceotaapi-android-1.5.2.jar')
}
app.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "visa.testapplication"
minSdkVersion 21
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation project(':moduleA')
implementation project(':moduleB')
}
App Level build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
gradle-wrapper.properties file
#Tue Oct 16 14:44:59 IST 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
Build Error Received
:app:mergeDebugAssets
:app:transformClassesWithDexBuilderForDebug
AGPBI: {"kind":"error","text":"Program type already present: com.bbpos.bb03z.c","sources":[{}],"tool":"D8"}
:app:transformDexArchiveWithExternalLibsDexMergerForDebug FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
> com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives: C:\work\TestApplication\app\build\intermediates\transforms\dexBuilder\debug\0.jar, C:\work\TestApplication\app\build\intermediates\transforms\dexBuilder\debug\1.jar, C:\work\TestApplication\app\build\intermediates\transforms\dexBuilder\debug\2.jar, C:\work\TestApplication\app\build\intermediates\transforms\dexBuilder\debug\3.jar, C:\work\TestApplication\app\build\intermediates\transforms\dexBuilder\debug\4.jar, C:\work\TestApplication\app\build\intermediates\transforms\dexBuilder\debug\5.jar, C:\work\TestApplication\app\build\intermediates\transforms\dexBuilder\debug\6.jar, C:\work\TestApplication\app\build\intermediates\transforms\dexBuilder\debug\7.jar, C:\work\TestApplication\app\build\intermediates\transforms\dexBuilder\debug\8.jar, C:\work\TestApplication\app\build\intermediates\transforms\dexBuilder\debug\9.jar, C:\work\TestApplication\app\build\intermediates\transforms\dexBuilder\debug\10.jar, C:\work\TestApplication\app\build\intermediates\transforms\dexBuilder\debug\11.jar, C:\work\TestApplication\app\build\intermediates\transforms\dexBuilder\debug\12.jar, C:\work\TestApplication\app\build\intermediates\transforms\dexBuilder\debug\13.jar, C:\work\TestApplication\app\build\intermediates\transforms\dexBuilder\debug\14.jar, C:\work\TestApplication\app\build\intermediates\transforms\dexBuilder\debug\15.jar, C:\work\TestApplication\app\build\intermediates\transforms\dexBuilder\debug\16.jar, C:\work\TestApplication\app\build\intermediates\transforms\dexBuilder\debug\17.jar, C:\work\TestApplication\app\build\intermediates\transforms\dexBuilder\debug\18.jar, C:\work\TestApplication\app\build\intermediates\transforms\dexBuilder\debug\19.jar, C:\work\TestApplication\app\build\intermediates\transforms\dexBuilder\debug\20.jar, C:\work\TestApplication\app\build\intermediates\transforms\dexBuilder\debug\21.jar, C:\work\TestApplication\app\build\intermediates\transforms\dexBuilder\debug\22.jar, C:\work\TestApplication\app\build\intermediates\transforms\dexBuilder\debug\23.jar, C:\work\TestApplication\app\build\intermediates\transforms\dexBuilder\debug\24.jar, C:\work\TestApplication\app\build\intermediates\transforms\dexBuilder\debug\25.jar, C:\work\TestApplication\app\build\intermediates\transforms\dexBuilder\debug\26.jar, C:\work\TestApplication\app\build\intermediates\transforms\dexBuilder\debug\27.jar, C:\work\TestApplication\app\build\intermediates\transforms\dexBuilder\debug\28.jar, C:\work\TestApplication\app\build\intermediates\transforms\dexBuilder\debug\29.jar, C:\work\TestApplication\app\build\intermediates\transforms\dexBuilder\debug\30.jar, C:\work\TestApplication\app\build\intermediates\transforms\dexBuilder\debug\31.jar, C:\work\TestApplication\app\build\intermediates\transforms\dexBuilder\debug\32.jar, C:\work\TestApplication\app\build\intermediates\transforms\dexBuilder\debug\33.jar, C:\work\TestApplication\app\build\intermediates\transforms\dexBuilder\debug\34.jar, C:\work\TestApplication\app\build\intermediates\transforms\dexBuilder\debug\35.jar, C:\work\TestApplication\app\build\intermediates\transforms\dexBuilder\debug\36.jar, C:\work\TestApplication\app\build\intermediates\transforms\dexBuilder\debug\37.jar, C:\work\TestApplication\app\build\intermediates\transforms\dexBuilder\debug\38.jar, C:\work\TestApplication\app\build\intermediates\transforms\dexBuilder\debug\39.jar, C:\work\TestApplication\app\build\intermediates\transforms\dexBuilder\debug\40.jar
* 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.
* Get more help at https://help.gradle.org
BUILD FAILED in 56s
In Android Studio, Change the View from Android to Project and inside your app >> libs paste your .jar files
Then right click on your .jar file and select Add As Library
It will sync your project and added as gradle dependency
I am going to develop Android on my company.
I downloaded Android Studio 3.1 and created a new blank project I get an error.
Gradle download will cause an unconditional error.
I referenced a lot of Google stuff, but I could not solve it.
Build gradle :
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.3'
}
}
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.fouad.kurd"
minSdkVersion 18
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.+'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}
gradle.wrapper.properties:
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
:(
Error Screen shot
Please Help me
You won't be able to use constraintLayout with target sdk version 28
So the main culprit is
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
So please remove the constraint layout or reduce the target sdk version to 27.
check if you have disabled offline mode of Android Studio.
Use implementation 'com.android.support:appcompat-v7:28.0.0-beta01' instead of 28.+
My project includes many modules, and I want to enable static code analyze for some of them. Thus I do following test, but it failed. Below is my library's build.gradle.
apply plugin: 'com.android.library'
android {
compileSdkVersion 26
defaultConfig {
minSdkVersion 16
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
lintOptions {
abortOnError true
ignoreWarnings false
checkReleaseBuilds true
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}
And below is my app's build.gradle.
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.example.hp.myapplication"
minSdkVersion 16
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
lintOptions {
abortOnError true
ignoreWarnings false
checkReleaseBuilds true
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
compile project(':mylibrary')
}
And I add a lint error in my library, below is mylibrary lint and ./gradlew assembleRelease result
hpdeMac-Pro:MyApplication hp$ ./gradlew mylibrary:lint
> Configure project :app
Configuration 'compile' in project ':app' is deprecated. Use 'implementation' instead.
> Task :mylibrary:lint
Ran lint on variant release: 2 issues found
Ran lint on variant debug: 2 issues found
Wrote HTML report to file:///Users/hp/Downloads/MyApplication/mylibrary/build/reports/lint-results.html
Wrote XML report to file:///Users/hp/Downloads/MyApplication/mylibrary/build/reports/lint-results.xml
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':mylibrary:lint'.
> Lint found errors in the project; aborting build.
Fix the issues identified by lint, or add the following to your build script to proceed with errors:
...
android {
lintOptions {
abortOnError false
}
}
...
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
* Get more help at https://help.gradle.org
BUILD FAILED in 1s
23 actionable tasks: 7 executed, 16 up-to-date
hpdeMac-Pro:MyApplication hp$ ./gradlew assembleRelease
> Configure project :app
Configuration 'compile' in project ':app' is deprecated. Use 'implementation' instead.
BUILD SUCCESSFUL in 0s
51 actionable tasks: 1 executed, 50 up-to-date
hpdeMac-Pro:MyApplication hp$
Would you like to explain why ./gradlew assembleRelease can't find the lint error and how to enable static code check for modules only? Thanks a lot.