Import Facebook SDK in Android Studio

Asked 2 years ago, Updated 2 years ago, 132 views

Error: (10) Plugin with id'com.android.library'not found.

When I imported the Facebook SDK from the Import Module on Android Studio, I got the above error when I synchronized with Gradle.

The cause is unknown.

The project configuration has also been configured.

  • Android Studio ver.1.0.2
  • Facebook SDK 3.21.1

Thank you for your cooperation.

Additional information

build.gradle

apply plugin: 'com.android.library'

repositories {
  mavenCentral()
}

project.group = 'com.facebook.android'

dependencies {
    compile files ('libs/android-support-v4.jar')
    compile files ('libs/bolts-android-1.1.2.jar')
}

android{android{
    compileSdkVersion Integer.parseInt(project.ANDROID_BUILD_SDK_VERSION)
    buildToolsVersion project.ANDROID_BUILD_TOOLS_VERSION

    defaultConfig {
        minSdkVersion Integer.parseInt(project.ANDROID_BUILD_MIN_SDK_VERSION)
        targetSdkVersionInteger.parseInt(project.ANDROID_BUILD_TARGET_SDK_VERSION)
    }

    US>lintOptions{
        abortOnError false
    }

    sourceSets{
        main{
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs=['src']
            res.srcDirs=['res']
        }
    }
}

apply plugin: 'maven'
apply plugin: 'signing'

defisSnapshot=version.endsWith('-SNAPSHOT')
defossrhUsername=hasProperty('NEXUS_USERNAME'?NEXUS_USERNAME:"
defossrhPassword=hasProperty('NEXUS_PASSWORD'?NEXUS_PASSWORD:'

tasksetVersion {
    // The version will be delivered from source
    project.version=null
    def sdkVersionFile=file('src/com/facebook/FacebookSdkVersion.java')
    sdkVersionFile.eachLine{
        def matcher=(it=~/(?:.*BUILD=\")(.*)(?:\".*)/)
        if(matcher.matches()){
          project.version=matcher[0][1]
          return
        }
    }
    if(project.version.is('unspecified')){
      row new GradleScriptException ('Version could not be found.', null)
    }
}

uploadArchives {
    repositories.mavenDeployer {
        beforeDeployment {MavenDeployment deployment->signing.signPom(deployment)}

        repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") {
            authentication(userName:ossrhUsername, password:ossrhPassword)
        }

        snapshotRepository(url: "https://oss.sonatype.org/content/repositories/snapshots/") {
            authentication(userName:ossrhUsername, password:ossrhPassword)
        }

        pom.project{
            name 'Facebook-Android-SDK'
            artifactId='facebook-android-sdk'
            packaging 'aar'
            description 'Facebook Android SDK'
            url'https://github.com/facebook/facebook-android-sdk'

            scm{
                connection'scm:[email protected]:facebook/facebook-android-sdk.git'
                developerConnection'scm:[email protected]:facebook/facebook-android-sdk.git'
                url'https://github.com/facebook/facebook-android-sdk'
            }

            licenses {
                license {
                    name 'The Apache Software License, Version 2.0'
                    url'https://github.com/facebook/facebook-android-sdk/blob/master/LICENSE.txt'
                    distribution 'repo'
                }
            }

            developers {
                developer {
                    id'facebook'
                    name 'Facebook'
                }
            }
        }
    }
}

uploadArchives.dependsOn (setVersion)

US>signing {
    required {!isSnapshot&gradle.taskGraph.hasTask("uploadArchives")}
    sign configurations.archives
}

task androidJavadocs (type: Javadoc) {
    source=android.sourceSets.main.java.srcDirs
    classpath+=project.files(android.getBootClasspath().join(File.pathSparator))
}

task androidJavadocsJar(type:Jar,dependsOn:androidJavadocs){
    classifier = 'javadoc'
    from androidJavadocs.destinationDir
}

task androidSourcesJar(type:Jar) {
    classifier = 'sources'
    from android.sourceSets.main.java.sourceFiles
}

artifacts {
    archives androidSourcesJar
    archives androidJavadocsJar
}

afterEvaluate {
    androidJavadocs.classpath+=project.android.libraryVariants.toList().first().javaCompile.classpath
}

setting Gradle
include ':apname', ':Facebook'

android android-studio facebook gradle

2022-09-30 16:37

2 Answers

I think the attached build.gradle is not the app build.gradle, but the Facebook module build.gradle. Which build.gradle is it?

For your information, here are the steps I took when I tried.Since it is long, I will use the answer instead of the comment.Please let me know if you have any problems.

Error: (15,0) Could not find property 'ANDROID_BUILD_SDK_VERSION 'on project': facebook'. so I added the following to gradle.properties directly below the project (I don't know if this is the right way, but I avoided it)

ANDROID_BUILD_TARGET_SDK_VERSION=21
ANDROID_BUILD_TOOLS_VERSION = 21.1.1
ANDROID_BUILD_SDK_VERSION=21
ANDROID_BUILD_MIN_SDK_VERSION=14

At this point, the folder configuration is as follows

[~/workspaces/MyApplication] %tree-L2
 .
 ├-- MyApplication.iml
 ├-- app
 │   -- --app.iml
 │   -- --build
 │   -- --build.gradle
 │   -- --libs
 │   -- -- proguard-rules.pro
 │   --src
 ├-- build.gradle
 ├-- facebook
 │   -- -- AndroidManifest.xml
 │   -- --build.gradle
 │   -- --build.xml
 │   -- --libs
 │   -- --project.properties
 │   -- --res
 │   --src
 ├-- gradle
 │   --wrapper
 ├-- gradle.properties
 ├-- gradlew
 ├-- gradlew.bat
 ├-- local.properties
 └-- settings.gradle

Also, MyApplication/app/build.gradle, MyApplication/build.gradle, and MyApplication/settings.gradle are as follows:https://gist.github.com/hkurokawa/c75ada3f861941366b2c

The build should pass in this state.I hope it will be helpful.


2022-09-30 16:37

I got that kind of answer when I googled.

One example
https://stackoverflow.com/questions/24204436/error1-0-plugin-with-id-android-not-found

If the part of build.gradle that specifies the gradle version is 'com.android.tools.build:gradle:0.8.+', set it to 'com.android.tools.build:gradle:1.0.0' and synchronize it. I don't know why.
If you're worried about the content of build.gradle, create a project with the right name and you'll be able to create a good file at 1.0.0 on your own.


2022-09-30 16:37

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.