简体   繁体   English

在Android Studio中导入Facebook库:找不到属性'ANDROID_BUILD_SDK_VERSION'

[英]Importing Facebook library in Android Studio: Could not find property 'ANDROID_BUILD_SDK_VERSION'

I want to import a library project into my app but whenever I try to do so , Android Studio doesn't recognise it 我想将一个库项目导入我的应用程序,但每当我尝试这样做时,Android Studio都无法识别它

It also gives me errors in build.gradle .. 它还给我build.gradle中的错误..

The Library is : PagerSlidingTabStrip .... 图书馆是:PagerSlidingTabStrip ....

Here are some pictures : 这是一些图片:

在此输入图像描述

在此输入图像描述

I have been trying to make it work for 3 days so far !! 到目前为止,我一直试图让它工作3天! Please Help Me :) 请帮我 :)

EDIT: 编辑:

apply plugin: 'android-library'

dependencies {
compile 'com.android.support:support-v4:19.0.0'
}

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

defaultConfig {
    minSdkVersion 8
    targetSdkVersion Integer.parseInt(project.ANDROID_BUILD_TARGET_SDK_VERSION)
}

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

 apply from: 'https://raw.github.com/chrisbanes/gradle-mvn-push/master/gradle-mvn-push.gradle'

EDIT2 : 编辑2:

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring project ':Sahertoday'.
> Could not resolve all dependencies for configuration ':Sahertoday:_debugCompile'.
> Could not find com.astuetz:pagerslidingtabstrip:1.0.1.
 Required by:
     Saher-3:Sahertoday:unspecified

* Try:
 Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get         more log output.

 BUILD FAILED

First of all, you can add this dependency to your project, without compiling the lib locally. 首先,您可以将此依赖项添加到项目中,而无需在本地编译lib。

dependencies {
    compile 'com.astuetz:pagerslidingtabstrip:1.0.1'
}

Otherwise if you would like to compile this lib locally, you have to define these keys in gradle.properties in the root. 否则,如果要在本地编译此lib,则必须在根目录中的gradle.properties中定义这些键。

ANDROID_BUILD_TARGET_SDK_VERSION=19
ANDROID_BUILD_TOOLS_VERSION=19
ANDROID_BUILD_SDK_VERSION=19

EDIT 编辑

There is also a GUI way for doing this. 这样做还有一种GUI方式。 It is accessed by selecting the module facebook in the project tree and pressing f4 . 通过在项目树中选择模块facebook并按f4来访问它。
Also you can just right-click the facebook and go to Open Module Settings near the bottom. 您也可以右键单击facebook并转到底部附近的“ Open Module Settings

It is shown in the pictures. 它显示在图片中。 The numbers in the picture are top sdk version at the time of writing. 在撰写本文时,图片中的数字是顶级sdk版本。

第一个块 - 图片中的数字与上面的数字不匹配,但那是因为我稍后更新了它们。

第二个块 - 相同的更新

There is a simpler solution. 有一个更简单的解决方案。 The constants like ANDROID_BUILD_SDK_VERSION can be replaced with normal version "numbers". ANDROID_BUILD_SDK_VERSION这样的常量可以替换为普通版本的“数字”。 So instead of 而不是

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

    defaultConfig {
         minSdkVersion 8
         targetSdkVersion Integer.parseInt(project.ANDROID_BUILD_TARGET_SDK_VERSION)
    }

..file can look like this: ..file可以是这样的:

android {
    compileSdkVersion 19
    buildToolsVersion '19.1.0'

    defaultConfig {
         minSdkVersion 15
         targetSdkVersion 19
    }

Go the facebook folder which you have imported in your project. 转到您在项目中导入的facebook文件夹。 Copy the gradle.properties file and paste in into your facebook module.It will remove the errors. 复制gradle.properties文件并粘贴到您的facebook模块中。它将删除错误。

For those who ran into same problems while adding libraries and still can't get it work. 对于那些在添加库时遇到同样问题的人仍然无法使其工作。 The following local include of the .aar file worked for me: 以下本地包含.aar文件为我工作:

  • Just download the .aar file from the maven repo manually. 只需手动从maven仓库下载.aar文件即可。
  • In Android Studio go to File -> new Module -> import .JAR or .AAR package and select your downloaded .aar file. 在Android Studio中,转到文件 - >新模块 - >导入.JAR或.AAR包,然后选择下载的.aar文件。

Android Studio does the rest (in the build.gradle) for you. Android Studio为您完成剩下的工作(在build.gradle中)。 Maybe clean and rebuild your project. 也许清理并重建你的项目。

apply plugin: 'com.android.library'

android {
    compileSdkVersion 22
    buildToolsVersion "22.0.1"

    defaultConfig {
        minSdkVersion 8
        targetSdkVersion 4
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
}

dependencies {
    compile 'com.android.support:appcompat-v7:22.2.1'
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM