Build error when trying to add Firebase dependency to Qt project - android

I would like to use Firebase the same way as in any native Android app non using Qt (i.e. using Java). I'm already have one (all is working fine).
Now I'm trying to add Firebase to my existing Qt project. For now, I'm trying to add all the required dependencies to build.gradle (so I can use Firebase APIs in my Java source code part of my Qt project), and getting weird errors.
I'm not good in Gradle so any help is appreciated (if this is possible at all, because I'm using quite old Qt 5.12.12).
This is build.gradle I have (builds and runs fine):
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.0'
}
}
repositories {
google()
jcenter()
}
apply plugin: 'com.android.application'
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar', '*.aar'])
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
implementation 'com.google.code.gson:gson:2.7'
implementation 'com.jakewharton:process-phoenix:2.1.2' // https://github.com/JakeWharton/ProcessPhoenix
implementation 'me.dm7.barcodescanner:zxing:1.9.13' // https://github.com/dm77/barcodescanner
}
android {
/*******************************************************
* The following variables:
* - androidBuildToolsVersion,
* - androidCompileSdkVersion
* - qt5AndroidDir - holds the path to qt android files
* needed to build any Qt application
* on Android.
*
* are defined in gradle.properties file. This file is
* updated by QtCreator and androiddeployqt tools.
* Changing them manually might break the compilation!
*******************************************************/
// Buggy thing: fails to build. Needs to be replaced with actual numbers.
// https://stackoverflow.com/a/46290586/3765267
/*compileSdkVersion androidCompileSdkVersion.toInteger()
buildToolsVersion androidBuildToolsVersion*/
compileSdkVersion 30
buildToolsVersion "30.0.2"
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = [qt5AndroidDir + '/src', 'src', 'java']
aidl.srcDirs = [qt5AndroidDir + '/src', 'src', 'aidl']
res.srcDirs = [qt5AndroidDir + '/res', 'res']
resources.srcDirs = ['src']
renderscript.srcDirs = ['src']
assets.srcDirs = ['assets']
jniLibs.srcDirs = ['libs']
}
}
lintOptions {
abortOnError false
}
}
This is build.gradle with all the dependencies I try to add (I've added classpath 'com.google.gms:google-services:4.3.14' to dependencies section and apply plugin: 'com.google.gms.google-services' line):
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.0'
classpath 'com.google.gms:google-services:4.3.14'
}
}
repositories {
google()
jcenter()
}
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar', '*.aar'])
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
implementation 'com.google.code.gson:gson:2.7'
implementation 'com.jakewharton:process-phoenix:2.1.2' // https://github.com/JakeWharton/ProcessPhoenix
implementation 'me.dm7.barcodescanner:zxing:1.9.13' // https://github.com/dm77/barcodescanner
}
android {
/*******************************************************
* The following variables:
* - androidBuildToolsVersion,
* - androidCompileSdkVersion
* - qt5AndroidDir - holds the path to qt android files
* needed to build any Qt application
* on Android.
*
* are defined in gradle.properties file. This file is
* updated by QtCreator and androiddeployqt tools.
* Changing them manually might break the compilation!
*******************************************************/
// Buggy thing: fails to build. Needs to be replaced with actual numbers.
// https://stackoverflow.com/a/46290586/3765267
/*compileSdkVersion androidCompileSdkVersion.toInteger()
buildToolsVersion androidBuildToolsVersion*/
compileSdkVersion 30
buildToolsVersion "30.0.2"
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = [qt5AndroidDir + '/src', 'src', 'java']
aidl.srcDirs = [qt5AndroidDir + '/src', 'src', 'aidl']
res.srcDirs = [qt5AndroidDir + '/res', 'res']
resources.srcDirs = ['src']
renderscript.srcDirs = ['src']
assets.srcDirs = ['assets']
jniLibs.srcDirs = ['libs']
}
}
lintOptions {
abortOnError false
}
}
And now I'm getting the following weird error trying to build the project:
Generating Android Package
Input file: C:/Work/Source/build-fdm-Android_Qt_5_12_12_Clang_armeabi_v7a-Debug/ui/android-libfdm.so-deployment-settings.json
Output directory: C:/Work/Source/build-fdm-Android_Qt_5_12_12_Clang_armeabi_v7a-Debug/ui/android-build/
Application binary: C:/Work/Source/build-fdm-Android_Qt_5_12_12_Clang_armeabi_v7a-Debug/bin/libfdm.so
Android build platform: android-33
Install to device: No
FAILURE: Build failed with an exception.
* Where:
Build file 'C:\Work\Source\build-fdm-Android_Qt_5_12_12_Clang_armeabi_v7a-Debug\ui\android-build\build.gradle' line: 18
* What went wrong:
A problem occurred evaluating root project 'android-build'.
> ASCII
* 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 3s
Addition #1. I can build using Qt 6.4.1 + Firebase. The question is about Qt 5.12.12. I suspect the reason is too old Gradle version it's using (4.6) or something like that.

By default in android we declare the plugin dependencies in gradle root module. Seems like in qt project we have only one flat layer with only one build.gradle file. The good news is that we can declare plugin dependencies in settings.gradle as well
Make sure you connected the plugin in settings.gradle:
pluginManagement {
repositories {
gradlePluginPortal()
google()
mavenCentral()
}
plugins {
id 'com.android.application' version '7.3.1' apply false
id 'com.google.gms.google-services' version '4.3.10' apply false
}
}
now you can apply the plugins in build.gradle like this:
plugins {
id 'com.android.application'
id 'com.google.gms.google-services'
}
android { ... }

Related

Gradle error in Android Studio: Could not find “com.android.tools.build:gradle:7.1.1.”

I am trying to import a project from Eclipse into Android Studio.
In Eclipse I exported it to gradle and then imported it into Android Studio.
Note: I am new to gradle and have no insight to problem.
Now I get this error:
> Configure project :
Running gradle version: 6.8
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring root project 'aBooks'.
> Could not resolve all artifacts for configuration ':classpath'.
> Could not find com.android.tools.build:gradle:7.1.1.
Searched in the following locations:
-
https://repo.maven.apache.org/maven2/com/android/tools/build/gradle/7.1.1/gradle-7.1.1.pom
If the artifact you are trying to retrieve can be found in the repository but without metadata in 'Maven POM' format, you need to adjust the 'metadataSources { ... }' of the repository declaration.
Required by:
project :
The link given leads to a “404 Page not found”.
The gradle files on my system with “gradle-7” are:
The gradle file :
buildscript {
// added crl https://tomgregory.com/anatomy-of-a-gradle-build-script/
repositories {
mavenCentral()
}
println "Running gradle version: $gradle.gradleVersion"
dependencies {
classpath 'com.android.tools.build:gradle:7.1.1' // **original error here**
// https://mvnrepository.com/artifact/com.android.tools.build/gradle
// implementation group: 'com.android.tools.build', name: 'gradle', version: '7.1.0-alpha01'
// https://mvnrepository.com/artifact/com.android.tools.build/gradle/7.1.0-alpha01
}
}
apply plugin: 'com.android.application' // 'android'
dependencies {
implementation fileTree(dir: 'libs', include: '*.jar')
implementation project(':CRLibs')
implementation 'com.android.support:support-annotations:28.0.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
}
android {
compileSdk 26
buildToolsVersion "32.0.0"
buildFeatures {
prefab true
prefabPublishing true
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
// Move the tests to tests/java, tests/res, etc...
instrumentTest.setRoot('tests')
// Move the build types to build-types/<type>
// For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml,
...
// This moves them out of them default location under src/<type>/... which would
// conflict with src/ being used by the main source set.
// Adding new build types or product flavors should be accompanied
// by a similar customization.
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
dependenciesInfo {
includeInApk true
includeInBundle true
}
// no joy
plugins { // added crl https://developer.android.com/studio/releases/gradle-plugin#groovy
id 'com.android.application' version '7.0.0-alpha13' apply false
id 'com.android.library' version '7.0.0-alpha13' apply false
id 'org.jetbrains.kotlin.android' version '1.5.31' apply false
}
}
I tried changing ‘7.1.1’ to ‘7.2’ no change. I have no clue on how to fix this. All the answers given in my searches do not match the versions here or were no help.
EDIT1:
Added info. when I go to file->Project Structure & Project, I see
Note that the Gradle version is blank. If I enter 6.8 or 7.1.1 and click OK, I get the same results and then if I go back the Gradle version is blank.
Gradle version 6.8 is identified at the current version(see line 2 of the error message. Don't know if this means anything.
This is the list of my Gradel-6* files:
Add google() to your repositories { } block. The Android Gradle plugin is located there.
Have the same problem
this was my solution
classpath 'com.android.tools.build:gradle:7.2.0'

Qt Android output apk generated in ~/android-build\build\outputs\apk\debug

Problem: I want to use Android build system (gradle version 3) with Qt project, but this version of gradle (compared to old version 2) would change location of generated output apk file to be under $buildDir/outputs/apk/debug instead of $buildDir/outputs/apk (added debug folder), but when Qt Android kit tries to install app to Android device it only looks in old location, and fails to locate the apk file. I checked with Android Studio and its same which indicates gradle 3 is working normal
old location: $build_folder/android-build\build\outputs\apk\my.apk
New location: $build_folder/android-build\build\outputs\apk\debug\my.apk
Error (Compile):
adb: error: cannot stat
'D:/Qt/FireBase/build-client01-Android_for_armeabi_v7a_GCC_4_9_Qt_5_11_0_for_Android_armv73-Release/android-build//build/outputs/apk/android-build-debug.apk':
No such file or directory
This problem occurs only when I make changes to default build.gradle generated by Qt to set gradle to version 3, the default generated file have classpath set to old version 2.3.3,
old: classpath 'com.android.tools.build:gradle:2.3.3'
new : classpath 'com.android.tools.build:gradle:3.1.0
There are other changes I made, that also require change in gradle-wrapper.properties, here are updated files:
build.gradle
buildscript {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
}
dependencies {
//classpath 'com.android.tools.build:gradle:2.3.3'
classpath 'com.google.gms:google-services:4.0.1' // google-services plugin
classpath 'com.android.tools.build:gradle:3.1.0'
}
}
allprojects {
repositories {
jcenter()
//google() // Google's Maven repository
maven {
url "https://maven.google.com"
}
}
}
apply plugin: 'com.android.application'
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
}
android {
/*******************************************************
* The following variables:
* - androidBuildToolsVersion,
* - androidCompileSdkVersion
* - qt5AndroidDir - holds the path to qt android files
* needed to build any Qt application
* on Android.
*
* are defined in gradle.properties file. This file is
* updated by QtCreator and androiddeployqt tools.
* Changing them manually might break the compilation!
*******************************************************/
compileSdkVersion androidCompileSdkVersion.toInteger()
buildToolsVersion androidBuildToolsVersion
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = [qt5AndroidDir + '/src', 'src', 'java']
aidl.srcDirs = [qt5AndroidDir + '/src', 'src', 'aidl']
res.srcDirs = [qt5AndroidDir + '/res', 'res']
resources.srcDirs = ['src']
renderscript.srcDirs = ['src']
assets.srcDirs = ['assets']
jniLibs.srcDirs = ['libs']
}
}
lintOptions {
abortOnError false
}
}
dependencies {
// ...
//libfirebase_auth.a
//libfirebase_app.a
implementation 'com.google.firebase:firebase-core:16.0.1'
implementation 'com.google.firebase:firebase-auth:16.0.2'
implementation 'com.google.android.gms:play-services-base:15.0.1'
// Getting a "Could not find" error? Make sure you have
// added the Google maven respository to your root build.gradle
}
apply plugin: 'com.google.gms.google-services'
gradle-wrapper.properties
#Mon Feb 20 10:43:22 EST 2017
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
I use this on my build.gradle :
android {
...
applicationVariants.all { variant ->
variant.outputs.all {
outputFileName = "../" + outputFileName
}
}
}
I still don't know where and how to instruct Qt to look into new output structure, but as a workaround for now , I added configuration to build.gradle to make a copy of the generated apk back to ~/apk where Qt looks for!
// make a copy of APK from "$buildDir/outputs/apk/debug" back to "$buildDir/outputs/apk"
def archiveBuildTypes = ["release", "debug"];
applicationVariants.all { variant ->
variant.outputs.all { output ->
if (variant.buildType.name in archiveBuildTypes) {
def taskSuffix = variant.name.capitalize()
def assembleTaskName = "assemble${taskSuffix}"
if (tasks.findByName(assembleTaskName)) {
def copyAPKFolderTask = tasks.create(name: "archive${taskSuffix}", type: org.gradle.api.tasks.Copy) {
description "copy APK to old folder"
def sourceFolder = "$buildDir/outputs/apk/$output.baseName"
def destinationFolder = "$buildDir/outputs/apk"
print "Copy apk from: $sourceFolder into $destinationFolder\n"
from(sourceFolder)
into destinationFolder
eachFile { file ->
file.path = file.name // so we have a "flat" copy
}
includeEmptyDirs = false
}
tasks[assembleTaskName].finalizedBy = [copyAPKFolderTask]
}
}
}
}
Update:
gradle 3.1.x and higher require at least androidBuildToolsVersion 27, while Qt currently supports no higher than androidBuildToolsVersion 26, So practically may be its safer to fall back to gradle 3.0.x which supports build tools 26
It's also even possible to fall back to gradle 2.3.3 (use compile instead of implementation for FireBase and any required modules:
compile 'com.google.firebase:firebase-core:16.0.1'
...

Writing Gradle script to run unit test cases for Eclipse Android Test project

I have a simple HelloWorld Android project (built in Eclipse IDE), I am able to do "gradle build" successfully in cmd prompt for this project.
Also I have written a simple JUnit Android Test Project for it, and it runs fine in Eclipse.
Now I want to run this Test Project or Unit Test Cases (if my understanding is wrong!) using Gradle script.
How do I do that?
Following is the build.gradle file I am using. I want to know how to write script code to automate the test case execution.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.10.+'
}
}
apply plugin: 'android'
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
}
android {
compileSdkVersion 19
buildToolsVersion "19.0.3"
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
test {
java.srcDirs = ['src/test/java']
resources.srcDirs = ['src/test/resources']
}
// Move the tests to tests/java, tests/res, etc...
instrumentTest.setRoot('tests')
androidTest.setRoot('tests')
// Move the build types to build-types/<type>
// For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
// This moves them out of them default location under src/<type>/... which would
// conflict with src/ being used by the main source set.
// Adding new build types or product flavors should be accompanied
// by a similar customization.
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
}
Here is what I use:
android {
// ...
// your stuff
// ...
// So Android Studio can nicely edit the test files
sourceSets {
androidTest {
java.srcDir file('src/test/java')
}
}
}
// <Task to run tests>
sourceSets {
unitTest {
java.srcDir file('src/test/java')
}
}
configurations {
unitTestCompile.extendsFrom runtime
unitTestRuntime.extendsFrom unitTestCompile
}
task unitTest(type: Test, dependsOn: assemble) {
description = "run unit tests"
testClassesDir = project.sourceSets.unitTest.output.classesDir
classpath = project.sourceSets.unitTest.runtimeClasspath
}
check.dependsOn unitTest
// </Task to run tests>
dependencies {
// ...
// compile stuff
// ....
unitTestCompile files("$project.buildDir/classes/release")
unitTestCompile 'junit:junit:4.11'
}
Run your test:
gradlew unitTest
This solution is not yet implemented and tested. Work in progress, comments are welcomed.
After reading all user guide carefully, it is clear that there is no direct support for Eclipse Android Test projects. The reason is that new build system adopts Gradle(and Maven) style to have Unit test inside module/project.
But because Eclipse Android Test projects is still Android project, there is way to try
Add build.gradle see below to Eclipse Android Test project.
It should have compile project(':app') in dependencies
/* Android
* http://www.nodeclipse.org/projects/gradle
* Nodeclipse/Enide build.gradle template for classic Android project
* https://github.com/Nodeclipse/nodeclipse-1/blob/master/org.nodeclipse.enide.editors.gradle/docs/android/build.gradle
* Gradle Plugin User Guide:
* http://tools.android.com/tech-docs/new-build-system/user-guide
* Usage
* 1. put in project root
* 2. check version numbers
* 3. use from command line or with Gradle for Android http://marketplace.eclipse.org/content/gradle
* Support for this template
* https://github.com/nodeclipse/nodeclipse-1/issues/
* History
* 2014-03-13 android plugin updated to 0.9, see http://tools.android.com/tech-docs/new-build-system/migrating_to_09
* 2014-04-01 check for gradle version
* 2014-04-10 wrapper and runAndroidApplication tasks
* 2014-04-25 rename to run, add <<
* 2014-05-23 defaut plugin version 0.10.x
* 2014-06-06 show "boilerplate part"
* #author Paul Verest
*/
println GradleVersion.current().prettyPrint()
assert gradle.gradleVersion >= "1.10" // android plugin 0.10 requires Gradle 1.10, 1.11, 1.12
// after `gradle wrapper` it is possible to use './gradlew build' with Gradle version specified
task wrapper(type: Wrapper) {
gradleVersion = '1.12'
}
//{ "boilerplate part"
buildscript {
repositories {
mavenCentral()
//jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.10.+'
}
}
apply plugin: 'android'
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
//androidTestCompile 'com.jayway.android.robotium:robotium-solo:4.3.1'
// for multi-module project build (needs `settings.gradle`):
// reference needed modules or App under test (for Eclipse Android Test project)
compile project(':app')
}
android {
compileSdkVersion 19
buildToolsVersion "19.0.3"
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
// Move the tests to tests/java, tests/res, etc...
androidTest.setRoot('tests')
// Move the build types to build-types/<type>
// For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
// This moves them out of them default location under src/<type>/... which would
// conflict with src/ being used by the main source set.
// Adding new build types or product flavors should be accompanied
// by a similar customization.
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
}
//} "boilerplate part"
Because app and its test now make multi-module project add settings.gradle. The easiest way to put it 1 level down (folder where both project are)
include ':app'
include ':apptest'
Other way is to put in sibling folder, e.g. called parent
includeFlat 'app'
includeFlat 'apptest'
In later case you would need to run build from that folder (or specify each time settings.gradle location with -c CLI option
UPDATE Doing research about pure JUnit tests with gradle (a bit offtopic for this question), it seems like Android Tooling team overlooks this question, breaking what others developers are trying to do with newer android gradle plugin. Even in Android Studio it is not so even How can I create tests in Android Studio? . The only orgnization that cares is Robolectric contributors that have its framework ready for pure JUnit testing https://github.com/robolectric/gradle-android-test-plugin

Run JUnit tests in Gradle for Android app

I want to run simple, plain JUnit tests in my Android app project, using Gradle at the same time to write Activity tests afterwards. It took a loong time to configure Gradle and make it work, but, anyway, now I'm stuck trying to make JUnit tests just compile.
I checked this link, but when I run gradle I get the following error:
DummyTest.java:3: error: package junit.
framework does not exist
import junit.framework.Assert;
^
\DummyTest.java:8: error: cannot find symbol
Assert.assertEquals(5,3);
^
symbol: variable Assert
location: class DummyTest
So, junit is not found...
The following is my full gradle.build file:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.6.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
dependencies {
compile files('libs/joda-time-2.3.jar')
compile files('libs/android-support-v4.jar')
unitTestCompile files("$project.buildDir/classes/release")
unitTestCompile 'junit:junit:4.8.2'
}
android {
compileSdkVersion 17
buildToolsVersion '17.0.0'
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
}
unitTest {
java.srcDir file('test')
resources.srcDir file('test/res')
}
}
defaultConfig {
minSdkVersion 14
versionName '1.0'
versionCode 1
targetSdkVersion 17
}
}
// add the unitTest task
task unitTest(type:Test, dependsOn: assemble) {
description = "run unit tests"
testClassesDir = project.sourceSets.unitTest.output.classesDir
classpath = project.sourceSets.unitTest.runtimeClasspath
}
build.dependsOn unitTest
AndroidStudio and the new Android Gradle plugin are now offering official unit test support.
This is supported from Android Studio 1.1+ and Android Gradle plugin version 1.1.0+
Dependencies can now be declared as testCompile:
dependencies {
testCompile 'junit:junit:4.12'
testCompile "org.mockito:mockito-core:1.9.5"
}
More details here: Unit testing support - Android Tools Project Site.
Have a look at this stackoverlfow thread: junit testing with gradle for an android project
It looks like he's doing exactly what you need.
I think the problem in your script is, that you havn't declared a
unitTest sourceset explicitly.
cheers,
René

Gradle can't find dependency (Android support library)

I have a problem that Gradle can't find my dependency (Android support library).
My build.gradle looks like this:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.4'
}
}
apply plugin: 'android'
dependencies {
compile files('libs/FlurryAgent.jar')
compile group: 'com.google.android', name: 'support-v4', version: 'r7'
compile files('libs/YouTubeAndroidPlayerApi.jar')
}
android {
compileSdkVersion 17
buildToolsVersion "17"
defaultConfig {
minSdkVersion 11
targetSdkVersion 17
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
instrumentTest.setRoot('tests')
}
}
When I build (on commandline, no IDE) I get the following message:
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring root project 'AndroidCalculator'.
> Failed to notify project evaluation listener.
> Could not resolve all dependencies for configuration ':compile'.
> Could not find com.google.android:support-v4:r7.
Required by:
:AndroidCalculator:unspecified
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Why am I not allowed to add the Android Support library like this?
You have declared a repository dependency, but haven't declared a repository. Hence the dependency cannot be resolved. (Repositories/dependencies in the buildscript block are strictly separated from repositories/dependencies in the main build script.)
http://pastebin.com/FmcCZwA5
This paste is elaborate project with AndroidAnnotations, Dagger, Jackson and Robolectric.
all you need is add
repositories {
mavenCentral()
}
replace
compile group: 'com.google.android', name: 'support-v4', version: 'r7'
with (line 44 of the code linked above)
compile 'com.android.support:support-v4:18.0.+'
Gotchas: Last bit will works on Android Studio 0.2+ only if you had a fresh install. Since 0.2 Studio is shipped with its internal m2 repo to provide support and google api libraries so if you upgraded from previous versions your SDK doesn't have it.
also make sure local.properties file is present in root folder and sdk.dir points to SDK
You need to add additional dependency in dependencies tag. If you have android-support-v4.jar library in your libs folder, try to add code listed below:
dependencies {
compile files('libs/android-support-v4.jar')
}

Categories

Resources