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

not able to include altbeacon library into new project

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

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

我试图探索 Whosebug 上的几乎所有线程,但无法弄清楚我应该怎么做才能解决它。

作为参考,我正在粘贴 AltBeacon 库的 build.gradle

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
  gradle.properties
  build.gradle
  app
    build.gradle
  1. 在上面的 beacon 文件夹中克隆 Android Beacon Library 存储库:

    git clone https://github.com/AltBeacon/android-beacon-library.git
    

    这应该给你这样的结构:

    beacon
      settings.gradle
      build.gradle
      app
        build.gradle
      android-beacon-library
    
  2. 将项目的 settings.gradle 文件更改为如下所示(添加第一行):

    include ':android-beacon-library'
    include ':app'
    
  3. 编辑 app/build.gradle 的依赖部分,使其看起来像这样:

    dependencies {
      ...
      compile project(':android-beacon-library')
    }
    

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