android - 无法将altbeacon库包含到新项目中

标签 android android-studio gradle altbeacon

我正在尝试将现有的android库添加到我的新项目中。我正在使用的现有库是AltBeacon库,我能够成功编译它。

之后,我通过在新的新android项目中作为模型导入添加了AltBeacon库,并添加到了gradle中。现在,当我尝试运行新项目时,出现以下错误。

我试图探究StackOverflow上的几乎所有线程,但无法弄清楚该怎么做。

enter image description here

作为引用,我正在粘贴build.gradleAltBeacon

ext {
    isSnapshot = !project.hasProperty('release')
    isSnapCi = System.getenv('SNAP_CI') != null
    isSnapPullRequest = System.getenv('SNAP_PULL_REQUEST_NUMBER') != null
}

/*
 * Gets the version name from the latest Git tag
 */
def getVersionName = {
    def stdout = new ByteArrayOutputStream()
    try {
        exec {
            commandLine 'git', 'describe', '--tags'
            standardOutput = stdout
        }
        return stdout.toString().trim()
    }
    catch (e) {
        println("Can't get version from git: " + e);
        return "adhoc"
    }
}

buildscript {
    repositories {

        maven {
            url 'https://maven.google.com'
        }
        maven {
            url 'https://dl.google.com/dl/android/maven2/'
        }
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'
        classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3'
        classpath 'org.jfrog.buildinfo:build-info-extractor-gradle:3.0.3'
    }
}

apply plugin: 'com.android.library'

apply from: 'gradle/eclipse.gradle'

allprojects {
    version = "${getVersionName()}${isSnapshot == true ? "-SNAPSHOT" : ""}"
    group = "org.altbeacon"

    repositories {
        google()
        jcenter()
        maven {
            url 'https://maven.google.com'
        }
        maven {
            url 'https://dl.google.com/dl/android/maven2/'
        }
    }
}

android {
    compileSdkVersion 28
    buildToolsVersion '28.0.0'

    defaultConfig {
        // Unfortunately 'com.android.support:appcompat-v7:26.0.0'
        // requires minSdkVersion 14, forcing a bump verson minSdkVersion 7
        // But since only 0.8% of Android devices have < SDK 14 as of Une 2017, this will become
        // the new min version for this library in order to target Android O
        minSdkVersion 14
        targetSdkVersion 28
        versionCode 1
        versionName version
        consumerProguardFiles 'proguard-rules.pro'
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }

    compileOptions {
        encoding "UTF-8"
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }

    lintOptions {
        abortOnError false
    }

    packagingOptions {
        exclude 'LICENSE.txt'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE'
    }
}

configurations {
    doclava
}



dependencies {
    compile fileTree ( dir: 'libs', include: ['*.jar'] )
    compile 'com.android.support:support-v4:28.0.0-rc02'
    compile 'com.android.support:support-annotations:28.0.0-rc02'

    testCompile 'com.google.android:android-test:4.1.1.4'
    testCompile('junit:junit:4.12') {
        exclude group: 'org.hamcrest'
    }
    testCompile('org.hamcrest:hamcrest-junit:2.0.0.0') {
        exclude group: 'junit'
    }
    testCompile('com.squareup:fest-android:1.0.+@aar')
    testCompile('org.robolectric:robolectric:3.0') {
        exclude group: 'junit'
    }
    testCompile('org.mockito:mockito-core:1.10.19') {
        exclude group: 'org.hamcrest'
    }
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
        exclude group: 'org.hamcrest'
    })
    androidTestCompile 'org.apache.commons:commons-math3:3.6.1'
    doclava 'com.google.doclava:doclava:1.0.6'
}

apply plugin: 'idea'

idea {
    module {
        testOutputDir = file('build/test-classes/debug')
    }
}

task renameAarForRelease(type: Copy, dependsOn: build) {
    description = "Rename the aar for easy release publishing"

    from "$buildDir/outputs/aar/" //${project.name}-release.aar
    into "$buildDir/outputs/aar/" //${project.name}-${project.version}.aar"
    include "${project.name}-release.aar"
    rename { String fileName ->
        fileName = "${project.name}-${project.version}.aar"
    }
}

task distribution(dependsOn: [bundleEclipse, build, clean, renameAarForRelease]) << {
    println "Building with version=$version"
}

task release(dependsOn: 'distribution') << {
    println('Doing release build')
}

android.libraryVariants.all { variant ->

    task("generate${variant.name}Javadoc", type: Javadoc) {
        title = "Android Beacon Library $version API"
        description "Generates Javadoc for $variant.name."
        source = variant.javaCompile.source
        ext.androidJar =
                "${android.sdkDirectory}/platforms/${android.compileSdkVersion}/android.jar"
        classpath = files(variant.javaCompile.classpath.files, ext.androidJar)
        options.linksOffline "http://d.android.com/reference/", "${android.sdkDirectory}/docs/reference"
        exclude '**/BuildConfig.java'
        exclude '**/R.java'
    }

}

task generateJavadoc(type: Javadoc, dependsOn: project.configurations.doclava) {
    failOnError = true
    title = null
    source = android.sourceSets.main.java.srcDirs
    options.doclet = "com.google.doclava.Doclava"
    options.docletpath = configurations.doclava.files.asType(List)
    classpath +=
            project.files(android.getBootClasspath().join(File.pathSeparator)) + configurations.compile

    destinationDir = file("../javadocs/")
}

build.mustRunAfter clean

apply from: 'gradle/credentials.gradle'
apply from: 'gradle/compile.gradle'
apply from: 'gradle/publishing.gradle'
apply from: 'gradle/bintray.gradle'
apply from: 'gradle/artifactory.gradle'

artifactoryPublish {
    // Skip deploying to artifactory if building a pull request
    onlyIf { !isSnapPullRequest }
}

我的新项目的 build.gradle
apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.absense"
        minSdkVersion 21
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {



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

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation project(':alt')
}

最佳答案

如果您要将Android Beacon库编译为与项目链接的源代码,那么如果您具有这样的两层项目设置(假设您的项目名为“beacon”,则最简单):

beacon
  gradle.properties
  build.gradle
  app
    build.gradle
  • 在上面的beacon文件夹内克隆Android Beacon库存储库:
    git clone https://github.com/AltBeacon/android-beacon-library.git
    

    这应该给你这样的结构:
    beacon
      settings.gradle
      build.gradle
      app
        build.gradle
      android-beacon-library
    
  • 更改项目的settings.gradle文件,使其看起来像这样(添加第一行):
    include ':android-beacon-library'
    include ':app'
    
  • 编辑app / build.gradle的dependencies部分,如下所示:
    dependencies {
      ...
      compile project(':android-beacon-library')
    }
    

  • 您可以在库reference application中看到此设置的示例,尽管注释了第2部分和第3部分以强制从JCenter加载该库。如果您想尝试使用引用,只需取消注释这些行,并注释掉这样的行:compile 'org.altbeacon:android-beacon-library:2+'

    关于android - 无法将altbeacon库包含到新项目中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52967374/

    相关文章:

    android - GPU 监控在 Android Studio 1.4 中不起作用

    android - 如何显示来自 Android 库的反编译 Kotlin 代码

    android - Android API和Gradle版本

    android - 从Android项目构建jar文件时,任务 ':app:kaptGenerateStubsDebugKotlin'的执行失败

    java - 软件包在android studio中不存在

    java - 如何处理 Java 中的网络连接问题

    java - AndroidHttpClient 无法解析为类型

    android - 如何使用安卓ViewPager?

    Android:recyclerview 中 View 项目的轮廓与 recyclerview 边框重叠

    android-studio - Gradle构建工具版本在哪里设置?