I'm making my first android wear app, but I can't get Android Studio working.
First I got the error
"Project with path ':wear' could not be found in project ':mobile'.
This was resolved by adding "include ':wear" in settings.gradle.
But then a new error occurs:
"Error:Module version Test2:mobile:unspecified, configuration 'wearApp' declares a dependency on configuration 'default' which is not declared in the module descriptor for Test2:wear:unspecified" .
What do I have to do to resolve that error?
Just in case it's needed: here's build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.verbraeken.joost.test2"
minSdkVersion 19
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
wearApp project(':wear')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.google.android.gms:play-services:8.3.0'
compile 'com.android.support:design:23.1.1'
}
settings.gradle:
include ':mobile'
include ':wear'
In Android Studio 3.0 the documentation for Migrate to the New Plugin says:
dependencies {
// This is the old method and no longer works for local
// library modules:
// debugCompile project(path: ':foo', configuration: 'debug')
// releaseCompile project(path: ':foo', configuration: 'release')
// Instead, simply use the following to take advantage of
// variant-aware dependency resolution. You can learn more about
// the 'implementation' configuration in the section about
// new dependency configurations.
implementation project(':foo')
// You can, however, keep using variant-specific configurations when
// targeting external dependencies. The following line adds 'app-magic'
// as a dependency to only the 'debug' version of your module.
debugImplementation 'com.example.android:app-magic:12.3'
}
So change this
debugCompile project(path: ':foo', configuration: 'debug')
releaseCompile project(path: ':foo', configuration: 'release')
to this
implementation project(':foo')
Error:Module version Test2:mobile:unspecified, configuration 'wearApp' declares a dependency on configuration 'default'
It means that a module (wearApp in your case) doesn't have a build.gradle file or a right configuration inside the build.gradle file.
Since you define a module in settings.gradle you have to provide a build.gradle for each module.
In your case:
root
|-- mobile
|----build.gradle
|-- wear
|----build.gradle
|--build.gradle
|--settings.gradle
If you're not using Android Studio 3.0, this worked for me, in your build.gradle lib:
publishNonDefault true
like this
android {
compileSdkVersion maxApiLevel.toInteger()
buildToolsVersion androidBuildToolsVersion
publishNonDefault true
[...]
}
And in your include build.gradle:
dependencies {
debugCompile project(path: ':foo', configuration: 'debug')
releaseCompile project(path: ':foo', configuration: 'release')
}
I am using ionic cordova for build my app, in my case the file build.grade was updated each time, I have to change the file "app_path>node_modules\cordova-android\bin\templates\cordova\lib\builders\GradleBuilder.js" from:
console.log('Subproject Path: ' + p);
var libName=p.replace(/[/\\]/g, ':').replace(name+'-','');
depsList += ' debugCompile(project(path: "' + libName + '", configuration: "debug"))';
insertExclude(p);
depsList += ' releaseCompile(project(path: "' + libName + '", configuration: "release"))';
insertExclude(p);
to:
console.log('Subproject Path: ' + p);
var libName=p.replace(/[/\\]/g, ':').replace(name+'-','');
depsList += ' compile project(\'' + libName + '\')';
insertExclude(p);
Works for me
The trick is:
dependencies {
// If the main app and wearable modules have the same flavors,
// the following configuration uses automatic dependency matching.
wearApp project(':wearable')
}
You don't have t set flavor or type build now, gradle 3.0 and above search for each flavor and buildType.
More info: https://developer.android.com/studio/build/gradle-plugin-3-0-0-migration#variant_dependencies
Related
I recently installed the latest Canary build of Android Studio which is currently using the Android Gradle plugin 3.0.0-alpha4 .
I now get a error:
Error:Failed to resolve: Could not resolve project :MyLib.
Required by:
project :app
I has read: Migrate dependency configurations for local modules
dependencies
{
// This is the old method and no longer works for local
// library modules:
// debugCompile project(path: ':foo', configuration: 'debug')
// releaseCompile project(path: ':foo', configuration: 'release')
// Instead, simply use the following to take advantage of
// variant-aware dependency resolution. You can learn more about
// the 'implementation' configuration in the section about
// new dependency configurations.
implementation project(':foo')
// You can, however, keep using variant-specific configurations when
// targeting external dependencies. The following line adds 'app-magic'
// as a dependency to only the 'debug' version of your module.
debugImplementation 'com.example.android:app-magic:12.3'
}
I changed:
releaseCompile project(path: ':MyLib', configuration: 'appReleaseApp')
debugCompile project(path: ':MyLib', configuration: 'appDebug')
to:
implementation project(':MyLib')
but i still have this error: Error:Failed to resolve: Could not resolve project :MyLib.
lib gradle:
apply plugin: 'com.android.library'
android {
publishNonDefault true
compileSdkVersion 25
buildToolsVersion "25.0.3"
defaultConfig {
minSdkVersion 14
targetSdkVersion 25
}
buildTypes {
debug {
...
}
releaseApp {
...
}
releaseSdk {
...'
}
}
flavorDimensions "default"
productFlavors {
flavor1{
...
flavor2{
...
}
flavor3{
...
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:support-v4:25.3.1'
compile 'com.google.code.gson:gson:2.8.0'
compile 'com.google.android.gms:play-services-maps:10.2.6'
compile 'com.google.android.gms:play-services-gcm:10.2.6'
compile 'com.google.android.gms:play-services-location:10.2.6'
}
apply plugin: 'maven'
uploadArchives {
repositories {
mavenDeployer {
repository(url: mavenLocal().url)
}
}
}
app gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.3"
defaultConfig {
vectorDrawables.useSupportLibrary = true
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
minSdkVersion 19
targetSdkVersion 25
versionCode 12
versionName "5.0.2"
}
buildTypes {
release {
...
}
debug {
...
}
}
flavorDimensions "default"
productFlavors {
flavor1 {
...
}
flavor2 {
...
}
}
testOptions {
unitTests {
all {
jvmArgs '-noverify'
systemProperty 'robolectric.logging.enable', true
}
}
}
}
repositories {
flatDir {
dirs 'libs'
}
}
dependencies {
// releaseCompile project(path: ':MyLib', configuration: 'appRelease')
// debugCompile project(path: ':MyLib', configuration: 'appDebug')
implementation project(':MyLib')
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.google.android.gms:play-services-maps:10.2.6'
compile 'com.google.android.gms:play-services-location:10.2.6'
compile 'com.google.android.gms:play-services-analytics:10.2.6'
compile 'com.google.android.gms:play-services-gcm:10.2.6'
compile 'com.google.code.gson:gson:2.8.0'
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:design:25.3.1'
compile 'com.android.support:support-v4:25.3.1'
compile 'com.android.support:cardview-v7:25.3.1'
compile 'com.android.support:gridlayout-v7:25.3.1'
compile 'com.android.volley:volley:1.0.0'
compile 'com.facebook.stetho:stetho:1.4.1'
compile 'com.facebook.stetho:stetho-okhttp3:1.4.1'
compile 'com.android.support:percent:25.3.1'
compile 'com.android.support:recyclerview-v7:25.3.1'
compile 'com.squareup.picasso:picasso:2.5.2'
testCompile 'junit:junit:4.12'
testCompile 'org.mockito:mockito-core:2.1.0'
testCompile 'org.robolectric:robolectric:3.1.4'
testCompile 'org.assertj:assertj-core:1.7.1'
compile 'com.flipboard:bottomsheet-core:1.5.0'
compile 'com.flipboard:bottomsheet-commons:1.5.0'
compile 'com.android.support.constraint:constraint-layout:1.0.1'
}
apply plugin: 'com.google.gms.google-services'
Please help
Google added more instruction how to solve it: Resolve build errors related to dependency matching
Cause of build error:
Your app includes a build type that a library dependency does not.
For example, your app includes a "staging" build type, but a
dependency includes only a "debug" and "release" build type.
Note that there is no issue when a library dependency includes a build
type that your app does not. That's because the plugin simply never
requests that build type from the dependency.
Resolution
Use matchingFallbacks to specify alternative matches for a given build type, as shown below:
// In the app's build.gradle file.
android {
buildTypes {
debug {}
release {}
staging {
// Specifies a sorted list of fallback build types that the
// plugin should try to use when a dependency does not include a
// "staging" build type. You may specify as many fallbacks as you
// like, and the plugin selects the first build type that's
// available in the dependency.
matchingFallbacks = ['debug', 'qa', 'release']
}
}
}
After facing the same issue, I finally declared exactly the same buildTypes in both App and Modules' build.gradle files.
In your case, adding
buildTypes {
debug {}
releaseApp {}
releaseSdk {}
}
to your module's build.gradle should do the trick.
Be sure to change any "compile project" to "implementation project" too.
Hope it helps
With the new plugin, the variant-aware dependency resolution
implementation project(':MyLib')
needs to have exact matching build types. The migration guide describes this
For instance, it is not possible to make a 'debug' variant consume a
'release' variant through this mechanism because the producer and
consumer would not match. (In this case, the name 'debug' refers to
the published configuration object mentioned above in the Publishing
Dependencies section.) Now that we publish two configurations, one for
compiling and one for runtime, this old way of selecting one
configuration really doesn't work anymore.
So the old method of
releaseCompile project(path: ':foo', configuration: 'debug')
will not work anymore.
Example
With your example this would look like this:
In app build.gradle:
apply plugin: 'com.android.application'
android {
buildTypes {
debug {}
releaseApp {}
releaseSdk {}
}
...
dependencies {
implementation project(':MyLib')
}
}
In module/lib 'MyLib' build.gradle:
apply plugin: 'com.android.library'
android {
buildTypes {
debug {}
releaseApp {}
releaseSdk {}
}
}
Therefore the build type must exactly match, no more no less.
Using Build-Type Fallbacks
A new feature called "matchingFallbacks" can be used to define default buildtypes if a sub-module does not define the buildtype.
Use matchingFallbacks to specify alternative matches for a given build type (...)
For example if module/lib 'MyLib' gradle would look like this:
apply plugin: 'com.android.library'
android {
buildTypes {
debug {}
releaseLib {}
}
}
You could define the following in your app build.gradle:
apply plugin: 'com.android.application'
android {
buildTypes {
debug {}
releaseApp {
...
matchingFallbacks = ['releaseLib']
}
releaseSdk {
...
matchingFallbacks = ['releaseLib']
}
}
...
dependencies {
implementation project(':MyLib')
}
}
Missing Flavor Dimensions
Use missingDimensionStrategy in the defaultConfig block to specify the
default flavor the plugin should select from each missing dimension
android {
defaultConfig {
missingDimensionStrategy 'minApi', 'minApi18', 'minApi23'
...
}
}
I was facing the same problem, I found this migration page:
Build matching types
It states:
Select defaults for missing build types
If a consumer configures a build type that a producer does not, you need to manually match the consumer's build type to one from the producer. For example, if your app module configures a "staging" build type and its library module dependency, "mylibrary", does not, the Android plugin throws the following build error:
Error:Failed to resolve: Could not resolve project :mylibrary.
Required by: project :app
To resolve this error, you need to specify which build type from "mylibrary" the Android plugin should match to the app's "staging" build type. You can do this with the buildTypeMatching property in the app's build.gradle file, as shown below:
// Add the following to the consumer's build.gradle file.
android {
...
// Tells the Android plugin to use a library's 'debug' build type
// when a 'staging' build type is not available. You can include
// additional build types, and the plugin matches 'staging' to the
// first build type it finds from the one's you specify. That is,
// if 'mylibrary' doesn't include a 'debug' build type either, the
// plugin matches 'staging' with the producer's 'release' build type.
buildTypeMatching 'staging', 'debug', 'release'
}
Adding buildTypeMatching fixed it for me without creating unecessary types in my library
Today I also had the same problem after migrating to Android Studio 3.
The problem is the gradle is not able to resolve the certain libraries due to network issue. The reasons might be various.
If you work behind the proxy you need to add the proxy parameters in gradle.properties file:
systemProp.http.proxyHost=<proxy_host>
systemProp.http.proxyPort=<proxy_port
systemProp.https.proxyHost=<proxy_host>
systemProp.https.proxyPort=<proxy_port>
In my case I had one more issue. My company uses the self signed SSL certificate so the SSL connection had some problem. If same applies also for you, you can set the parameter again in gradle.properties file as follows:
org.gradle.jvmargs=-Djavax.net.ssl.trustStore="/usr/lib/jvm/java-8-oracle/jre/lib/security/cacerts" -Djavax.net.ssl.trustStoreType=JKS -Djavax.net.ssl.keyStorePassword=changeit
To be more clear you can click on "Show details" link in messages log in Android Studio. This log will be more helpful to decide what is the real problem.
This solution worked for me. I'm using Android Studio 3.1.2. Android Gradle plugin 3.1.2. Gradle 4.4. I have a library module with flavours such as trial and premium. As part of the process of migrating to the Android Gradle plugin 3.1.2 I added a flavour dimension of main to my library module's gradle build file. To correct the build error therefore in my app's build.gradle file I changed the following:
debugImplementation project(path: ':library', configuration: 'premiumDebug')
releaseImplementation project(path: ':library', configuration: 'premiumRelease')
became
implementation project(':library')
and I added the following line to my defaultConfig block: missingDimensionStrategy 'main', 'premium'
I'm trying to test an app from the command line. When I run my test from the Android Studio, everything goes fine. But when I try to run the command:
./gradlew test
I get this error:
Task 'test' not found in root project 'mvp_kotlin_example'.
I don't have problems using ./gradlew build or ./gradlew clean. I just created a project to try the ./gradlew test and it worked.
In mvp_kotlin_example I am using Robolectric for tests and Kotlin for development.
So how can I make my tests work from the command line?
Edit:
This is a open source project, so all the code can be found in the
https://github.com/leandroBorgesFerreira/mvp-kotlin-example
This is my build.gradle file:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply from: '../jacoco.gradle'
android {
compileSdkVersion 25
buildToolsVersion "25.0.0"
defaultConfig {
applicationId "br.com.simplepass.simplepassnew"
minSdkVersion 16
targetSdkVersion 25
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
testCoverageEnabled = true
}
}
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
testCompile "org.robolectric:robolectric:3.1.4"
testCompile 'com.squareup.okhttp3:mockwebserver:3.3.1'
testCompile 'org.khronos:opengl-api:gl1.1-android-2.1_r1'
testCompile "org.mockito:mockito-core:2.4.2"
compile 'com.android.support:appcompat-v7:25.1.0'
compile 'com.android.support:design:25.1.0'
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
compile 'br.com.simplepass:loading-button-android:1.5.0'
compile 'org.jetbrains.anko:anko-sdk15:0.9' // sdk19, sdk21, sdk23 are also available
compile 'io.reactivex:rxandroid:1.2.1'
compile 'io.reactivex:rxjava:1.1.6'
compile 'com.squareup.retrofit2:retrofit:2.1.0'
compile 'com.squareup.retrofit2:converter-gson:2.1.0'
compile 'com.squareup.retrofit2:adapter-rxjava:2.1.0'
compile 'com.squareup.okhttp3:logging-interceptor:3.3.1'
compile 'com.google.dagger:dagger:2.8'
kapt 'com.google.dagger:dagger-compiler:2.8'
provided 'org.glassfish:javax.annotation:10.0-b28'
}
repositories {
mavenCentral()
}
kapt {
generateStubs = true
}
Edit 2:
This is what I see after running ./gradlew tasks (it's a lot less tasks than the usuall)
------------------------------------------------------------
All tasks runnable from root project
------------------------------------------------------------
Build Setup tasks
-----------------
init - Initializes a new Gradle build. [incubating]
wrapper - Generates Gradle wrapper files. [incubating]
Help tasks
----------
buildEnvironment - Displays all buildscript dependencies declared in root project 'mvp_kotlin_example'.
components - Displays the components produced by root project 'mvp_kotlin_example'. [incubating]
dependencies - Displays all dependencies declared in root project 'mvp_kotlin_example'.
dependencyInsight - Displays the insight into a specific dependency in root project 'mvp_kotlin_example'.
help - Displays a help message.
model - Displays the configuration model of root project 'mvp_kotlin_example'. [incubating]
projects - Displays the sub-projects of root project 'mvp_kotlin_example'.
properties - Displays the properties of root project 'mvp_kotlin_example'.
tasks - Displays the tasks runnable from root project 'mvp_kotlin_example'.
Other tasks
-----------
clean
Here the problem has nothing to do with your build.gradle your project was missing the settings.gradle file that tells gradle to include the app folder as a module. I've created PR #1 on your project to resolve this defect, when merged you should be able to run ./gradlew clean test from the root project directory.
https://github.com/leandroBorgesFerreira/mvp-kotlin-example/pull/1
Solution is to just add a oneline settings.gradle file to the root project that declares the modules included in the build.
$ cat settings.gradle
include 'app'
I have an Android application module (app) and an Android library module (library). Both app and library contain these same dependencies:
dependencies {
compile 'com.squareup.okhttp:okhttp:2.4.0'
compile 'com.squareup.retrofit:retrofit:1.9.0'
compile 'io.reactivex:rxjava:1.0.13'
compile 'io.reactivex:rxandroid:0.25.0'
}
However when I try to add that block to the project build.gradle, it complains about not knowing the "compile" DSL.
EDIT: I'm asking about putting this dependencies block in the PROJECT build.gradle, to avoid repeating in each module's build.gradle.
As of Gradle Plugin version 3.0.0 there is a nicer way to do this. We can control whether each dependency is available for only the current module, or for the current module AND any modules which depend on it. This will allow us to easily share dependencies across modules within a project.
Here's how we used to declare dependencies:
compile 'example.dependency:1.0.0'
Here are the new configurations which should replace compile:
implementation 'example.dependency:1.0.0' --> this dependency is only used within this module
api 'example.dependency:1.0.0' --> this dependency will also be available in any builds that depend on this module
Here's how to do that with the architecture you mentioned in the question. Assuming that we have a module named 'library' that is consumed by the 'app' module, we can use the api configuration to declare that the dependency should be shared with any module that depends on it.
library module build.gradle
dependencies {
// dependencies marked 'implementation' will only be available to the current module
implementation 'com.squareup.okhttp:okhttp:2.4.0'
// any dependencies marked 'api' will also be available to app module
api 'com.squareup.retrofit:retrofit:1.9.0'
api 'io.reactivex:rxjava:1.0.13'
api 'io.reactivex:rxandroid:0.25.0'
}
app module build.gradle:
dependencies {
// declare dependency on library module
implementation project(':library')
// only need to declare dependencies unique to app
implementation 'example.dependency:1.0.0'
}
Please see this guide for further information and diagrams.
The dependencies block(closure) needs DependencyHandler as delegate
You need to pass DependencyHandler of each project to shared dependencies in project gradle.build.
project build.gradle
ext.sharedGroup = {dependencyHandler->
delegate = dependencyHandler
compile 'com.squareup.okhttp:okhttp:2.4.0'
compile 'com.squareup.retrofit:retrofit:1.9.0'
compile 'io.reactivex:rxjava:1.0.13'
compile 'io.reactivex:rxandroid:0.25.0'
}
app build.gradle
dependencies {
sharedGroup dependencies
}
ref. https://github.com/b1uec0in/DependencyVersionResolver
(see 2. Using default dependency group.
This sample explains many other tips for sharing library version, sdk versions ... for large project that have many modules.)
You can define shared gradle dependencies in the library module, and if the app module has the library as a dependency, you won't need to specify everything twice. Taking this further, you could create a 'common' module that requires the shared gradle dependencies, and have both the app & library module require the common module.
You could do something like this where the project build.gradle will specify the dependencies needed as variable names then in the app build.gradle files you just need to include the variable names. This is very useful when you have many modules and don't want to edit everyone when a version number changes!
project build.gradle
buildscript {
ext {
googlePlayServicesVersion = '7.5.0'
supportLibVersion = '22.2.0'
}
... (the rest of your repositories/dependency info here) ...
}
ext {
minSdkVersion=16
targetSdkVersion=21
buildToolsVersion='22.0.1'
compileSdkVersion=21
//Android Dependencies
supportV4 = 'com.android.support:support-v4:' + supportLibVersion
supportAnnotations = 'com.android.support:support-annotations:' + supportLibVersion
recyclerView = 'com.android.support:recyclerview-v7:' + supportLibVersion
cardView = 'com.android.support:cardview-v7:' + supportLibVersion
palette = 'com.android.support:palette-v7:' + supportLibVersion
appCompat = 'com.android.support:appcompat-v7:' + supportLibVersion
multidex = 'com.android.support:multidex:1.0.1'
appCompat = 'com.android.support:appcompat-v7:' + supportLibVersion
supportDesign = 'com.android.support:design:' + supportLibVersion
playServicesAnalytics = 'com.google.android.gms:play-services-analytics:' + googlePlayServicesVersion
}
app build.gradle file
dependencies {
compile rootProject.ext.supportV4
compile rootProject.ext.appCompat
compile rootProject.ext.supportAnnotations
compile rootProject.ext.recyclerView
compile rootProject.ext.cardView
compile rootProject.ext.palette
compile rootProject.ext.appCompat
compile rootProject.ext.multidex
compile rootProject.ext.supportDesign
compile rootProject.ext.playServicesAnalytics
}
Hope that this helps!
Share libraries using ext block in the root project module
This is an easy way to use the library across all modules in the
android project
Please follow these steps:
Add ext block (it is used to define extra properties for the project) in root project gradle file
Add common libraries in with variable name in ext block
e.g name = [
libraries without implementation keyword
]
Used this ext block in module level using implementation and variable name
e.g implementation variable_name
See below code for complete implementation
build.gradle :project
buildscript {
... (the rest of your repositories here) ...
}
ext { **// ext block start here**
appModuleLibraries = [
commonLibraries,
/*Projects*/
project(':hco-cutout'),
project(':utils')
]
commonLibraries = [
/*Android Libs*/
'androidx.core:core-ktx:1.7.0',
'androidx.appcompat:appcompat:1.4.1',
'com.google.android.material:material:1.5.0',
'androidx.constraintlayout:constraintlayout:2.1.3',
/*Gesture viw for image zooming */
'com.alexvasilkov:gesture-views:2.5.2',
]
cutoutModulleLibraries = [
commonLibraries,
project(':utils'),
// Selfie segmentation
'com.google.mlkit:segmentation-selfie:16.0.0-beta4',
/*checker board drawable*/
'com.github.duanhong169:checkerboarddrawable:1.0.2',
]
} **// ext block end here**
build.gradle :app
dependencies {
/*App Module Libraries in root project gradle*/
implementation appModuleLibraries
}
build.gradle :cutout
dependencies {
/*cutout Module Libraries in root project gradle*/
implementation cutoutModulleLibraries
implementation project(':utils')
}
Hope that this helps!
Based on #SMKS answer, I would prefer this solution for transitive option capability and simplicity
project build.gradle
buildscript {
... (the rest of your repositories/dependency info here) ...
}
ext {
googlePlayServicesVersion = '7.5.0'
supportLibVersion = '22.2.0'
}
app build.gradle file
dependencies {
compile 'com.android.support:support-v4:' + supportLibVersion
compile ' com.android.support:support-annotations:' + supportLibVersion
compile = 'com.android.support:recyclerview-v7:' + supportLibVersion {
transitive = true // do not know if this make sens/interest just for example
}
...
}
Hello I am working on a project for which I am using Android Studio. I have setup everything but when I run my project then I get below errors. I could not resolve it for last 2 days. What could be the problem in my project that causing this error
Please help if anyone know about this.
app build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "in.xyz"
minSdkVersion 15
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.0.+'
//compile files('libs/android-support-v4.jar')
compile 'com.android.support:support-v4:22.0.+'
compile 'com.android.support:support-annotations:20.0.0'
}
library build.gradle
apply plugin: 'com.android.library'
android {
compileSdkVersion 22
buildToolsVersion "21.1.2"
defaultConfig {
minSdkVersion 15
targetSdkVersion 22
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
//compile files('libs/android-support-v4.jar')
compile 'com.android.support:support-v4:22.0.+'
compile 'com.android.support:support-annotations:20.0.0'
}
build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.1.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
...
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Landroid/support/annotation/AnimRes;
at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:596)
at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:554)
at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:535)
at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)
at com.android.dx.merge.DexMerger.merge(DexMerger.java:189)
at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:454)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:303)
at com.android.dx.command.dexer.Main.run(Main.java:246)
at com.android.dx.command.dexer.Main.main(Main.java:215)
at com.android.dx.command.Main.main(Main.java:106)
Error:Execution failed for task ': app:dexDebug'.
settings.gradle
include ':app'
include ':multiStateToggleButton'
Your problem i believe is that wherever you are linking the Library to your Main Project you have the same dependencies between the two for your support library and annotations.
If you have the library project as a dependency in your application you will only need the dependency to be placed in the library dependencies closure.
The issue is that you have two dex files because there are two Files with the same name because the overlap in files with your dependencies.
First copy your module to your libs/ folder of your main project then,
create your settings.gradle file in the root of the main project:
include 'app_name', 'library_name'
project(':LibraryNameGoesHere').projectDir = new File('libs/LibraryNameGoesHere')
For your library's build.gradle
dependencies {
compile files('libs/android-support-v4.jar')
compile 'com.android.support:support-v4:22.0.+'
compile 'com.android.support:support-annotations:20.0.0'
}
Then for your main project build.gradle
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.0.+'
compile project(":libs:LibraryNameGoesHere")
}
Since facebook sdk configed for using Android 2.3.3, it requires annotaion lib.
My app configed for using Anndoid > 4.x.x, which is contains Annotation, the conflict was emarged.
I have changed, in the facebbok mainfest, to work with Android > 4.x.x and it solved the problem.
if you migrate the project from eclipse to studio , and then your project need a new module, you add the build.gradle which in the module, add the dependencies like this,
compile 'com.android.support:support-annotations:24.1.1'
compile 'com.android.support:support-v4:24.1.1'
//recyclerview
compile 'com.android.support:cardview-v7:21.0.3'
compile 'com.android.support:recyclerview-v7:21.0.3'
you might be see this stupid problem because the old project has include the jar file like android-support-v4.jar
this shit is overlay the compile(thing) so you must remove the *.jar file,
this shit takes my hole afternoon, so good luck ,my english is pool,
fogiven me please
For what it's worth I was getting this error after using Android Studio to import a project from Eclipse. In the /app/build.gradle file I had two entries in the dependencies section, it looked like this
dependencies {
compile files('libs/android-support-v13.jar')
compile files('libs/android-support-v4.jar')
}
I removed the reference to v4 like below
dependencies {
compile files('libs/android-support-v13.jar')
}
I cleaned the project and was able to build my APK. I don't know if this was the correct way to fix it but it worked for me.
I checked all the other threads about this topic but couldn't find an answer.
I am trying to import the Twoway View Project as a library into Android Studio.
Both projects run fine on their own but I always get the same Gradle Error: Error:Configuration with name 'default' not found when trying to import.
I have the project copied into a "libraries" directory in the root folder of my project and the following gradle structure:
settings.gradle of my project:
include ':libraries:twoway-view-master',':app'
build.gradle of "app":
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "app.com.jeldrik.teacherslittlehelper"
minSdkVersion 13
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
compile project(':libraries:twoway-view-master')
and in twoway-view-master build.gradle:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.0'
}
}
That twowayview-master build.gradle file isn't a buildscript for a standalone module; it lacks any sort of apply plugin statement that would tell Gradle how it should compile something. This looks like the top-level build file of a multimodule-structured project. In your settings.gradle file, you should point at the module in the project you're trying to include, not the build file at the top level.
Did you try it out using File -> New Module?
Or try setting the dependencies from here as well : File -> Project Structure -> Dependencies
I have recently got into same issue. As Scott said we have to include individual modules in our project's build.gradle file. This TwoWayView library has 3 different modules
core
layouts
sample
Say if you want to add core and layouts, add the below lines in your project's build.gradle file (Assuming you have twoway-view-master folder inside libraries folder which is inside your app folder).
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
compile project(':your-app-folder:libraries:twoway-view-master:core')
compile project(':your-app-folder:libraries:twoway-view-master:layouts')
}
Then add the same path to your project's settings.gradle file
include ':your-app-folder:libraries:twoway-view-master:core'
include ':your-app-folder:libraries:twoway-view-master:layouts'
NOTE: The build.gradle files inside core and layouts have wrong path to gradle-mvn-push.gradle file. So change the path from
apply from: "${rootDir}/gradle/scripts/gradle-mvn-push.gradle"
to
apply from: "${rootDir}/your-app-folder/libraries/twoway-view-master/gradle/scripts/gradle-mvn-push.gradle"
If you still get error in layouts' build.gradle file, change this line
compile project(':core')
to
compile project(':your-app-folder:libraries:twoway-view-master:core')
Do the same change if you're also using sample's build.gradle file in your project.