Java 在 Android Studio 中导入 Facebook 库:找不到属性“ANDROID_BUILD_SDK_VERSION”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21477884/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 08:53:57  来源:igfitidea点击:

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

javaandroidandroid-studiogradlepagerslidingtabstrip

提问by Ibrahim Al-Eidan

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 :

以下是一些图片:

enter image description here

enter image description here

在此处输入图片说明

在此处输入图片说明

I have been trying to make it work for 3 days so far !! Please Help Me :)

到目前为止,我一直在努力让它工作 3 天!!请帮我 :)

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

采纳答案by Gabriele Mariotti

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.

否则,如果你想在本地编译这个库,你必须在根目录的 gradle.properties 中定义这些键。

ANDROID_BUILD_TARGET_SDK_VERSION=19
ANDROID_BUILD_TOOLS_VERSION=19
ANDROID_BUILD_SDK_VERSION=19

回答by mdzeko

EDIT

编辑

There is also a GUI way for doing this. It is accessed by selecting the module facebookin the project tree and pressing f4.
Also you can just right-click the facebookand go to Open Module Settingsnear the bottom.

It is shown in the pictures. The numbers in the picture are top sdk version at the time of writing.

还有一种GUI方式可以做到这一点。通过facebook在项目树中选择模块并按来访问它f4
您也可以右键单击facebook并转到Open Module Settings底部附近。

它显示在图片中。图片中的数字是撰写本文时的顶级 sdk 版本。

first block - The numbers in the pictures don't match the above ones, but that's because I updated them later on.

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

second block - same update

第二个块 - 相同的更新

There is a simpler solution. The constants like ANDROID_BUILD_SDK_VERSIONcan be replaced with normal version "numbers". So instead of

有一个更简单的解决方案。ANDROID_BUILD_SDK_VERSION可以用普通版本的“数字”替换像这样的常量。所以代替

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
    }

回答by mmnger

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 repomanually.
  • In Android Studio go to File -> new Module -> import .JAR or .AAR package and select your downloaded .aar file.
  • 只需手动从Maven 存储库下载 .aar 文件。
  • 在 Android Studio 中,转到 File -> new Module -> import .JAR or .AAR package 并选择您下载的 .aar 文件。

Android Studio does the rest (in the build.gradle) for you. Maybe clean and rebuild your project.

Android Studio 为您完成剩下的工作(在 build.gradle 中)。也许清理并重建您的项目。

回答by Ankita

Go the facebook folder which you have imported in your project. Copy the gradle.properties file and paste in into your facebook module.It will remove the errors.

转到您在项目中导入的 facebook 文件夹。复制 gradle.properties 文件并粘贴到您的 facebook 模块中。它将删除错误。

回答by Dashrath Rathod

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'
}