I have added the below mentioned dependency and the repositories. But even after Sync and Rebuild, Facebook is not getting added and hence the import is not happening in the java file. This is as per the document provided by facebook. I have similar setup in other app. Please let me know if I am missing anything, I am trying to resolve this for more than a day. Please assist.
in module level build.
apply plugin: 'com.android.application'
android {
buildToolsVersion '28.0.2'
compileSdkVersion 28
dexOptions {
javaMaxHeapSize "4g"
}
defaultConfig {
applicationId "xxxxxxxxxxxxxxxxxx"
minSdkVersion 15
targetSdkVersion 28
// Enabling multidex support.
multiDexEnabled true
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
jniLibs.srcDirs = ['libs']
}
androidTest.setRoot('tests')
}
}
repositories {
mavenCentral()
google()
jcenter()
}
dependencies {
api project(':BaseGameUtils')
api files('libs/AudienceNetwork.jar')
api files('libs/FacebookAdapter.jar')
implementation files('libs/chartboost.jar')
implementation files('libs/chartboost-7.2.0.1.aar')
api 'com.android.support:multidex:1.0.3'
api 'com.facebook.android:facebook-android-sdk:4.36.1'
api 'com.google.firebase:firebase-core:16.0.1'
api 'com.google.firebase:firebase-analytics:16.0.1'
api 'com.google.firebase:firebase-invites:16.0.1'
api 'com.google.firebase:firebase-ads:15.0.1'
api 'com.google.firebase:firebase-messaging:17.1.0'
api 'com.google.firebase:firebase-appindexing:16.0.1'
api 'com.google.android.gms:play-services-analytics:16.0.1'
api 'com.google.android.gms:play-services-games:15.0.1'
api 'com.google.android.gms:play-services-identity:15.0.1'
api 'com.google.android.gms:play-services-plus:15.0.1'
}
Also tried this dependency, still not resolved
add this instead
implementation 'com.facebook.android:facebook-android-sdk:[4,5)'
Ensure you don't have 'Offline Work' enabled
File > Settings (or Preferences on Mac) > Gradle
Under Global Gradle settings, uncheck 'Offline work' (if checked).
Click 'OK'.
I was having the same issue, this resolved it for me.
Related
I'm just migrated from Eclipse. My project keeps the old structure like below
projRoot\
src\
res\
...
AndroidManifest.xml
tests
build.gradle
Here's content of build.gradle
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.12.+'
}
}
apply plugin: 'android'
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
}
android {
compileSdkVersion 19
buildToolsVersion '19.1.0'
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
androidTest.setRoot('tests/src')
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
defaultConfig {
testApplicationId 'com.xxx.yyy.test'
testInstrumentationRunner 'android.test.InstrumentationTestRunner'
testHandleProfiling true
testFunctionalTest true
}
}
I'm on Android Studio 0.8 beta, Gradle 1.12, I tried every possible solution found all over SO and google without any success.
Anyone can help out? Thanks.
In addition, where can I know the current version of Android Gradle plugin?
For test source set structure, follow this link. It is mentioned that test source sets should be setup as follows:
for local unit tests: module-name/src/test/java/
for android instrumentation tests: module-name/src/androidTest/java/
In case it's still doesn't work. Android Studio may encounter sometimes issues with the recognition of the tests. And the workaround would be to run local tests by using the command line:
./gradlew testVariantNameUnitTest
Once the command is run. You can go back to Android Studio and run the tests and it should work. You can find more on running tests using command line on this link.
Hope this helps.
Before adding a library to my Android project the layout was like this:
MyappProject
Myapp
build.gradle
settings.gradle
build.gradle
The top level build.gradle has always been empty, with the settings.gradle file containing only:
include ':Myapp'
I obtained a library project which I was able to import successfully into Android Studio, so I presume that the gradle files within it were fine. I now have the following structure:
MyappProject
Myapp
build.gradle
libraries
Library
LibrarySubProject1
build.gradle
....
build.gradle
settings.gradle
build.gradle
...and the top level settings gradle now looks like:
include ':Myapp'
include ':libraries:Library'
I've also updated Myapp's build.gradle so it includes the extra last line in dependencies here:
dependencies {
compile 'com.android.support:support-v4:+'
compile files('libs/commons-lang3-3.1.jar')
compile files('libs/jsoup-1.7.3.jar')
compile project(':libraries:Library')
}
Unfortunately, any attempt to do anything with gradle (sync files, build etc.) now gets me the following:
Gradle 'MyappProject' project refresh failed:
Configuration with name 'default' not found.
Gradle settings
Any changes to the settings appear to have no effect, and Android Studio keeps the settings set to "use default gradle wrapper".
From what I understand, that means that there is a problem with the top level build.gradle along the lines of this file not containing sufficient information to build the sub projects. But, perhaps I have misunderstood, as Myapp used to build and Library also seems fine. Removing the compile project(':libraries:Library') allows gradle file syncing again, but I would like to use that library...
Any suggestions as to how to fix this would be welcome.
Edited to add build.gradle from Library. Top level:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.9.+'
}
}
allprojects {
version = VERSION_NAME
group = GROUP
repositories {
mavenCentral()
}
}
From the next level:
apply plugin: 'android-library'
android {
compileSdkVersion 19
buildToolsVersion "19.0.3"
defaultConfig {
minSdkVersion 14
targetSdkVersion 19
}
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')
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
}
apply from: 'https://raw.github.com/chrisbanes/gradle-mvn-push/master/gradle-mvn-push.gradle'
You cannot have project inside a project in Android Studio. You can only have modules so change your project structure as shown below so that it will be compliant for the allowed project - module level structure.
MyappProject
Myapp
build.gradle
libraries
LibrarySubProject1
build.gradle
....
settings.gradle
build.gradle(Root only one)
Now do the following with your build.gradle files
1. Root level build.gradle file
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.9.+'
}
}
repositories {
mavenCentral()
}
If you have something in your library project's root level build.gradle file include that also in this root level build.gradle file because only root is allowed to have which will automatically be included in each of the sub level's build.gradle files while compilation .
2. LibraryProject's build.gradle file
apply plugin: 'android-library'
android {
compileSdkVersion 19
buildToolsVersion "19.0.3"
defaultConfig {
minSdkVersion 14
targetSdkVersion 19
}
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')
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
}
apply from: 'https://raw.github.com/chrisbanes/gradle-mvn-push/master/gradle-mvn-push.gradle'
3. Your main module's build.gradle file should look like
apply plugin: 'android'
android {
compileSdkVersion 19
buildToolsVersion "19.0.3"
defaultConfig {
minSdkVersion 14
targetSdkVersion 19
}
}
dependencies {
//YOUR MODULE DEPENDENCIES
compile project(':libraries:LibrarySubProject1')
}
your settings.gradle file will be like
include ':Myapp'
include ':libraries:LibrarySubProject1'
In my case the problem was solved simply by deleting the line containing
maven_push.gradle
this line was trying to upload the project to maven while I didn't need to.
Your library has a multimodule build file structure:
Library
LibrarySubProject1
build.gradle
....
build.gradle
with the two-level build.gradle file structure like Android Studio-made projects have, but that doesn't work for libraries. MyApp is pulling in the dependency for :libraries:Library but only sees that top-level build file with the buildscript and allprojects tags, and it can't find a default configuration in there to depend on.
Your library can't have a settings.gradle file to lead the way to LibrarySubProject1/build.gradle. What you'll need to move the library one directory level up to Library, and collapse the two build.gradle files down to one:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.9.+'
}
}
repositories {
mavenCentral()
}
apply plugin: 'android-library'
android {
compileSdkVersion 19
buildToolsVersion "19.0.3"
defaultConfig {
minSdkVersion 14
targetSdkVersion 19
}
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')
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
}
apply from: 'https://raw.github.com/chrisbanes/gradle-mvn-push/master/gradle-mvn-push.gradle'
I'm not sure what to do about the VERSION and GROUP stuff you're doing in the top-level build.gradle; you'll have to figure that out.
I just commented out line:
apply from: rootProject.file('gradle/maven-push.gradle') in
build.gradle(:library) since I don't want to publish this project at all, but I need it just as a library.
I'm trying to build my Android app in Android Studio, but I have got the following error:
Gradle: A problem occurred evaluating project ':libraries:facebook'.
> Gradle version 1.6 is required. Current version is 1.8
How can I fix it? I don't know what is wrong with my build.gradle file:
buildscript {
repositories {
maven { url 'http://repo1.maven.org/maven2' }
}
dependencies {
classpath 'com.android.tools.build:gradle:0.4'
}
}
apply plugin: 'android-library'
dependencies {
compile files('libs/android-support-v4.jar')
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 7
targetSdkVersion 16
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
res.srcDirs = ['res']
}
}
}
How can I fix it? Thanks in advance.
Update Android Studio to last release.
Then change:
classpath 'com.android.tools.build:gradle:0.8'
Modify your gradle/wrapper/gradle-wrapper.properties to use the 1.10 version of Gradle.
Also to improve your script, you can change this line
compile files('libs/android-support-v4.jar')
with
compile 'com.android.support:support-v4:18.0.0' //or 19.0.1
There is a relation between IDE, gradle-plugin and the gradle version.
relation between gradle version and gradle build tool version
I am trying to get Google Maps into my application from within Android Studio. I found a tutorial which suggested openning up my .grade file:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android'
and add this line to dependencies:
compile 'com.google.android.gms:play-services:3.2.25'
I added this line and my .grade file looks like this:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.6.+'
compile 'com.google.android.gms:play-services:3.2.25'
}
}
apply plugin: 'android'
dependencies {
}
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 added this line, and tried to rebuild my project I get this error:
Gradle: A problem occurred evaluating root project 'BeerPortfolioPro'.
> No signature of method: org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.compile() is applicable for argument types: (java.lang.String) values: [com.google.android.gms:play-services:3.2.25]
Possible solutions: module(java.lang.Object)
Update:
I tried changing my .grade from one of the answers below to this:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.6.+'
}
}
apply plugin: 'android'
dependencies {
compile 'com.google.android.gms:play-services:4.0.30'
}
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')
}
}
and now I get this error:
Gradle: A problem occurred configuring root project 'BeerPortfolioPro'.
> Failed to notify project evaluation listener.
> Could not resolve all dependencies for configuration ':_DebugCompile'.
> Could not find com.google.android.gms:play-services:4.0.30.
Required by:
:BeerPortfolioPro:unspecified
Open your SDK Manager and install/update the Android Support Repository, Android Support Library v19, Google Repository and Google Play Service v13.
I had a similar "No signature of method" error, and realised that I'd added the dependency to the wrong file. When creating my project, Android Studio created 2 build.gradle files, one in the project root directory (alongside local.properties and gradle.properties), and one in a subdirectory named after my app (alongside the src and build directories). The play-services dependency needs to be added to the latter of these files, not the former.
The dependencies block in your buildscript section is for including files required for the gradle build script. Google Play Services should be in the "app" `dependencies' section.
Here's a suggestion buildscript solution.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.6.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
android {
compileSdkVersion 19
buildToolsVersion "19"
defaultConfig {
minSdkVersion 11
targetSdkVersion 19
}
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')
}
dependencies {
compile 'com.android.support:support-v4:19.0.0'
compile 'com.google.android.gms:play-services:4.0.30'
}
Extra Notes
classpath 'com.android.tools.build:gradle:0.6.+'
This will make sure you have the latest gradle 6 build tools.
Also the following block will make sure you're using the latest SDK version and build tools, while still including SDK 11 as the minimum supported version. Build Tools v19.0.0 has improvements over previous versions, but also plays nicely with Java 7.
compileSdkVersion 19
buildToolsVersion "19.0.0"
defaultConfig {
minSdkVersion 11
targetSdkVersion 19
}
If you cannot reference play-service 4 then a temporary solution could be to reference play-services:3.2.25 as specified in the documentation. A better solution would be to upload the library to your own maven repository (like Sonatype Nexus) and pull the dependency from there.
It's the minSdkVersion problem. Change it to 14, for Android 4.0.
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 14
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.google.android.gms:play-services:4.0.30'
compile 'com.android.support:appcompat-v7:+'
}
I'm trying to migrate from Maven to Gradle with my project.
So far we used HoloEverywhere v1.6.1 and ABS v4.3.1 and with Maven everything worked fine.
Now I'm upgrading to HoloEverywhere v2.0.0-SNAPSHOT (latest master # https://github.com/Prototik/HoloEverywhere) and ABS v4.4.0
HoloEverywhere build.gradle is kept intact.
This is my project library build.gradle configuration:
apply plugin: 'android-library'
dependencies {
compile 'com.actionbarsherlock:actionbarsherlock:4.4.0#aar'
compile project(':contrib:holo-everywhere:library')
compile project(':contrib:holo-everywhere:addons:slider')
compile project(':contrib:holo-everywhere:addons:preferences')
}
android {
compileSdkVersion 18
buildToolsVersion "18.1"
defaultConfig {
minSdkVersion 8
targetSdkVersion 18
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
}
}
What am I missing here? Should I remove ABS here altogether because of new support-v4:18.0.1 library?
Yeah. Don't use ABS + HoloEverywhere v2.0.0+ together.
I accidentally checked the checkbox in Android Studio which adds the ActionBarCompact to the new project. Trying to add ABS gave me the same error. removing compile 'com.android.support:appcompat-v7:18.0.0' solves this issue.