error: duplicate class: android.support.v7.appcompat.R - android

When I try to compile my project I get this error message "Error:(9, 14) error: duplicate class: android.support.v7.appcompat.R". I'm using android studio and I have the latest SDK packages.
gradle for the module:
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "21.1.2"
defaultConfig {
minSdkVersion 14
targetSdkVersion 22
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.android.support:support-v4:22.0.0'
compile files('libs/commons-codec-1.10.jar')
compile "com.android.support:appcompat-v7:22.0.0"
}
Gradle file for the Project:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.1.0'
}
}
allprojects {
repositories {
jcenter()
}
}
these are my gradle files for the project

Move "compileOptions" outside of your "defaultConfig".
I also updated your "buildToolsVersion".
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "22.0.0"
defaultConfig {
minSdkVersion 14
targetSdkVersion 22
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
compileOptions { // <-- Moved this outside of your defaultConfig
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
}
dependencies {
compile files('libs/commons-codec-1.10.jar')
compile 'com.android.support:appcompat-v7:22.0.0' // <-- brings in support-v4
}

Related

How to fix Manifest merger failed

I imported GoogleMapsV2WithActionBarSherlock eclipse project and encountered
Error:Execution failed for task ':googleMapsV2:processDebugManifest'.
Manifest merger failed : Attribute meta-data#com.google.android.gms.version#value value=() from
[GoogleMapsV2WithActionBarSherlock:androidmapsutils:unspecified]
AndroidManifest.xml:8:13-29 is also present at
[com.google.android.gms:play-services-basement:11.0.2]
AndroidManifest.xml:20:66-119
value=(#integer/google_play_services_version). Suggestion: add
'tools:replace="android:value"' to element at
AndroidManifest.xml:6:9-8:32 to override.
Is anybody has a clue on what it is and how can I fix it?
Here are the list of the errors.
googleMapsV2 build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion "26.0.0"
defaultConfig {
applicationId "com.ecs.google.maps.v2.actionbarsherlock"
minSdkVersion 14
targetSdkVersion 17
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile project(':androidmapsutils')
compile project(':library')
compile 'com.google.code.gson:gson:2.1'
compile 'com.actionbarsherlock:actionbarsherlock:4.4.0#aar'
compile 'com.android.support:support-v4:18.0.0'
compile 'com.android.support:gridlayout-v7:18.0.0'
compile 'com.google.android.gms:play-services:+'
compile files('libs/commons-logging-1.1.1.jar')
compile files('libs/google-http-client-1.15.0-rc.jar')
compile files('libs/google-http-client-android-1.15.0-rc.jar')
compile files('libs/google-http-client-jackson2-1.15.0-rc.jar')
compile files('libs/httpclient-4.0.1.jar')
compile files('libs/httpcore-4.0.1.jar')
compile files('libs/jackson-core-2.1.3.jar')
compile files('libs/jackson-core-asl-1.9.11.jar')
}
androidmaputils build.gradle
apply plugin: 'com.android.library'
android {
compileSdkVersion 26
buildToolsVersion "26.0.0"
defaultConfig {
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.android.support:support-v4:21.0.0'
compile 'com.google.android.gms:play-services-maps:11.0.2'
}
GoogleMapsV2WithActionBarSherlock 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:2.2.0'
}
}
allprojects {
repositories {
jcenter()
}
}
PagerTabSlidingTabStrip build.gradle
apply plugin: 'com.android.library'
android {
compileSdkVersion 17
buildToolsVersion "26.0.0"
defaultConfig {
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.android.support:support-v4:18.0.0'
}
Check your build.gradle(app) minSdkVersion 14 and
compile 'com.google.android.gms:play-services-maps:11.0.2'
add tools:replace="android:value" to your manifest to the end of <application> tag

Gradle cannot find target sdk

I need to write a small library with submodules. When i try sync my project i get error.
if i use gradle gradle:1.0.1
Error:Configuration with name 'default' not found.
if build:gradle:1.2.3
Error:Cause: failed to find target 21
but this sdk already installed.
Here is my build.gradle
uildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.3'
}
}
apply plugin: 'com.android.library'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
minSdkVersion 9
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
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(':libs:UniversalImageLoader')
}
project(':libs:UniversalImageLoader') {
apply plugin: 'com.android.library'
android.compileSdkVersion = 21
android.buildToolsVersion = "21.1.2"
android.sourceSets.main {
manifest.srcFile 'library/AndroidManifest.xml'
java.srcDirs = ['library/src']
res.srcDirs = ['library/res']
}
}
Any ideas on this subject? Thx for help.

Robospock and gradle build variants?

I'm using Robospock to perform unit testing and mocking with gradle. This worked great until I added gradle build variants to the mix.
My android build.gradle file:
apply plugin: 'android-library'
android {
compileSdkVersion 19
buildToolsVersion "19.0.3"
defaultConfig {
minSdkVersion 16
targetSdkVersion 19
versionCode 1
versionName "0.0.1"
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
productFlavors {
uat {
packageName "com.acme.dev"
}
stage {
packageName "com.acme.staging"
}
prod {
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.google.code.gson:gson:2.2.4'
compile 'com.mcxiaoke.volley:library:1.0.4'
}
My robospock build.gradle file:
buildscript {
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.8.+'
classpath 'org.robospock:robospock-plugin:0.4.0'
}
}
repositories {
mavenCentral()
}
apply plugin: 'groovy'
dependencies {
compile "org.codehaus.groovy:groovy-all:1.8.6"
compile 'org.robospock:robospock:0.4.4'
compile 'cglib:cglib-nodep:2.2'
compile 'org.objenesis:objenesis:1.3'
}
project.ext {
robospock = ":Mothership" // project to test
}
apply plugin: 'robospock'
The Android gradle plug-in offers me build variant tasks such as assembleProd, assembleProdDebug, assembleStageDebugTest. Can I pass something to Robospocl in my build.gradle so that it can participate in the build variants?
Currently when I execute ./gradlew robospok, it cannot find the classes defined in com.acme.dev or com.acme.staging

Build script error, unsupported Gradle DSL method found: 'android()'!

I'm using Android Studio 0.4.5 and having troubles syncing gradle.
When I try to do that I get this error:
Gradle 'MyApp' project refresh failed: Build script error, unsupported Gradle DSL method found: 'android()'!
My solution contains 4 modules. Here is my root build.graddle:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.8.+'
}
}
android {
packagingOptions {
exclude 'META-INF/LICENSE.txt'
}
}
allprojects {
repositories {
mavenCentral()
}
}
And the others (I removed dependencies for simplicity)
Module 1
apply plugin: 'android'
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.8.+'
}
}buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.8.+'
}
}
android {
compileSdkVersion 19
buildToolsVersion "19.0.1"
defaultConfig {
minSdkVersion 9
targetSdkVersion 19
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
Module 2
apply plugin: 'android-library'
android {
compileSdkVersion 18
buildToolsVersion "19.0.1"
defaultConfig {
minSdkVersion 8
targetSdkVersion 17
}
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
Module 3
apply plugin: 'android-library'
android {
compileSdkVersion 18
buildToolsVersion "19.0.1"
defaultConfig {
minSdkVersion 8
targetSdkVersion 17
}
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
Module 4
apply plugin: 'android-library'
android {
compileSdkVersion 17
buildToolsVersion "19.0.1"
defaultConfig {
minSdkVersion 9
targetSdkVersion 17
}
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
Sorry for making this so long, but I'm getting desperate here :(
The main reason was having this:
android {
packagingOptions {
exclude 'META-INF/LICENSE.txt'
}
}
in the root build.gradle.
Remove following lines of code from Module1 build.gradle file :
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.8.+'
}
}buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.8.+'
}
}
As you are using the same configuration across all your modules, so it is fine to have it in root gradle file only.
Even if you want it in module's build.gradle file this code should be before applying android plugin.
Final Module1 build.gralde file :
apply plugin: 'android'
android {
compileSdkVersion 19
buildToolsVersion "19.0.1"
defaultConfig {
minSdkVersion 9
targetSdkVersion 19
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
Also make sure below mentioned configuration should be same across the modules
android {
compileSdkVersion 19
buildToolsVersion "19.0.1"
defaultConfig {
minSdkVersion 9
targetSdkVersion 19
}
}
You can use whatever you want but should be same.

Android Studio and google play services

I'm getting really frustrated with this. I've managed to make the google play services available in Android Studio but now I can't instantiate an AdView class. I can import import com.google.android.gms.ads.*; no errors there, it just says Unused import but when I try to create an AdView class I get a cannot find symbol error. It also doesn't find com.google.android.gms.ads.AdView or any other class inside that package for that matter.
I tried cleaning/re-building/restarting the IDE but nothing worked so far.
Here's my build.gradle file:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.7.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
android {
compileSdkVersion 19
buildToolsVersion '19.0.1'
defaultConfig {
minSdkVersion 15
targetSdkVersion 19
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
buildTypes {
release {
runProguard true
proguardFile getDefaultProguardFile('proguard-android.txt')
}
}
productFlavors {
defaultFlavor {
proguardFile 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.google.android.gms:play-services:4.0.30'
compile files('libs/libGoogleAnalyticsServices.jar')
}
Fixed
See this

Categories

Resources