无法在我的旧Android项目中添加生物识别支持API

问题描述 投票:0回答:3

在成为iOS开发人员8年半之后,我在4个月前开始学习andorid,并且我获得了Cordova andorid项目。任务是整合指纹和面部识别登录。

我目前的项目(非常古老的项目)中有什么:

build gradle:2.3.3 gradle版本:3.3 cordova-android版本:5.1.4

我知道这些都很老了。

我在过去10天里到目前为止所做的尝试:

我尝试将上面升级到最新的build gradle和gradle版本。一堆又一堆的错误出现了。

我已经尝试在build.gradle和build-extra.gradle中逐一添加生物度量支持库..但没有任何作用......

我的问题:

  1. 为什么我不能添加生物度量支持库当我有一切编译并在build gradle 2.3.3和gradle 3.3上正常工作?
  2. 我是否必须将gradle和每个支持库版本更新到最新版本?如果是,那么它会导致代码问题吗?让我说我已经使用了任何旧的UI组件,当我尝试将旧的支持库与新的生物识别API合并时,它会产生编译时错误。我尝试过这个。
  3. 任何人都可以告诉我一步一步升级这个项目,以便即使有编译时错误我可以删除那些然后一切正常后我可以添加生物识别支持库。
  4. 最后,生物识别支持库可以集成到任何旧项目中,这就是为什么它们被称为支持库。如果我错了,请纠正我。

我在MAC OSX上使用Android studio

以下是文件:

Build-extra.gradle:

 ext.postBuildExtras = {
    android {
        compileOptions {
            sourceCompatibility JavaVersion.VERSION_1_7
            targetCompatibility JavaVersion.VERSION_1_7
        }
        useLibrary 'org.apache.http.legacy'
    }

    dependencies {
        //compile 'com.google.android.gms:play-services:8.4.0'
        compile 'com.android.support:appcompat-v7:23.3.0'
        compile "com.squareup.picasso:picasso:2.4.0"
        compile "com.android.support:design:25.0.0"
        compile "com.google.firebase:firebase-messaging:9.2.0" //FCM Config
        compile 'com.rmtheis:tess-two:6.0.2'
        compile 'com.github.bumptech.glide:glide:3.8.0'
        compile 'com.android.support:support-v4:19.1.0'
    }
}

的build.gradle

// GENERATED FILE! DO NOT EDIT!

apply plugin: 'com.android.application'

buildscript {
    repositories {
        jcenter{ url "http://jcenter.bintray.com/" }
    }

    // Switch the Android Gradle plugin version requirement depending on the
    // installed version of Gradle. This dependency is documented at
    // http://tools.android.com/tech-docs/new-build-system/version-compatibility
    // and https://issues.apache.org/jira/browse/CB-8143
    dependencies {
        classpath 'com.android.tools.build:gradle:2.3.3'
        classpath "com.google.gms:google-services:3.0.0" //FCM Config

    }
   }


// Allow plugins to declare Maven dependencies via build-extras.gradle.
repositories {
    mavenCentral()
}

task wrapper(type: Wrapper) {
    gradleVersion = '2.8'
}

// Configuration properties. Set these via environment variables, build-extras.gradle, or gradle.properties.
// Refer to: http://www.gradle.org/docs/current/userguide/tutorial_this_and_that.html
ext {
    apply from: 'CordovaLib/cordova.gradle'
    // The value for android.compileSdkVersion.
    if (!project.hasProperty('cdvCompileSdkVersion')) {
        cdvCompileSdkVersion = null;
    }
    // The value for android.buildToolsVersion.
    if (!project.hasProperty('cdvBuildToolsVersion')) {
        cdvBuildToolsVersion = null;
    }
    // Sets the versionCode to the given value.
    if (!project.hasProperty('cdvVersionCode')) {
        cdvVersionCode = null
    }
    // Sets the minSdkVersion to the given value.
    if (!project.hasProperty('cdvMinSdkVersion')) {
        cdvMinSdkVersion = null
    }
    // Whether to build architecture-specific APKs.
    if (!project.hasProperty('cdvBuildMultipleApks')) {
        cdvBuildMultipleApks = null
    }
    // .properties files to use for release signing.
    if (!project.hasProperty('cdvReleaseSigningPropertiesFile')) {
        cdvReleaseSigningPropertiesFile = null
    }
    // .properties files to use for debug signing.
    if (!project.hasProperty('cdvDebugSigningPropertiesFile')) {
        cdvDebugSigningPropertiesFile = null
    }
    // Set by build.js script.
    if (!project.hasProperty('cdvBuildArch')) {
        cdvBuildArch = null
    }

    // Plugin gradle extensions can append to this to have code run at the end.
    cdvPluginPostBuildExtras = []
}

// PLUGIN GRADLE EXTENSIONS START
// PLUGIN GRADLE EXTENSIONS END

def hasBuildExtras = file('build-extras.gradle').exists()
if (hasBuildExtras) {
    apply from: 'build-extras.gradle'
}

// Set property defaults after extension .gradle files.
if (ext.cdvCompileSdkVersion == null) {
    ext.cdvCompileSdkVersion = privateHelpers.getProjectTarget()
}
if (ext.cdvBuildToolsVersion == null) {
    ext.cdvBuildToolsVersion = privateHelpers.findLatestInstalledBuildTools()
}
if (ext.cdvDebugSigningPropertiesFile == null && file('debug-signing.properties').exists()) {
    ext.cdvDebugSigningPropertiesFile = 'debug-signing.properties'
}
if (ext.cdvReleaseSigningPropertiesFile == null && file('release-signing.properties').exists()) {
    ext.cdvReleaseSigningPropertiesFile = 'release-signing.properties'
}

// Cast to appropriate types.
ext.cdvBuildMultipleApks = cdvBuildMultipleApks == null ? false : cdvBuildMultipleApks.toBoolean();
ext.cdvMinSdkVersion = cdvMinSdkVersion == null ? null : Integer.parseInt('' + cdvMinSdkVersion)
ext.cdvVersionCode = cdvVersionCode == null ? null : Integer.parseInt('' + cdvVersionCode)

def computeBuildTargetName(debugBuild) {
    def ret = 'assemble'
    if (cdvBuildMultipleApks && cdvBuildArch) {
        def arch = cdvBuildArch == 'arm' ? 'armv7' : cdvBuildArch
        ret += '' + arch.toUpperCase().charAt(0) + arch.substring(1);
    }
    return ret + (debugBuild ? 'Debug' : 'Release')
}

// Make cdvBuild a task that depends on the debug/arch-sepecific task.
task cdvBuildDebug
cdvBuildDebug.dependsOn {
    return computeBuildTargetName(true)
}

task cdvBuildRelease
cdvBuildRelease.dependsOn {
    return computeBuildTargetName(false)
}

task cdvPrintProps << {
    println('cdvCompileSdkVersion=' + cdvCompileSdkVersion)
    println('cdvBuildToolsVersion=' + cdvBuildToolsVersion)
    println('cdvVersionCode=' + cdvVersionCode)
    println('cdvMinSdkVersion=' + cdvMinSdkVersion)
    println('cdvBuildMultipleApks=' + cdvBuildMultipleApks)
    println('cdvReleaseSigningPropertiesFile=' + cdvReleaseSigningPropertiesFile)
    println('cdvDebugSigningPropertiesFile=' + cdvDebugSigningPropertiesFile)
    println('cdvBuildArch=' + cdvBuildArch)
    println('computedVersionCode=' + android.defaultConfig.versionCode)
    android.productFlavors.each { flavor ->
        println('computed' + flavor.name.capitalize() + 'VersionCode=' + flavor.versionCode)
    }
}

android {
    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
            jniLibs.srcDirs = ['libs']
        }
    }

    defaultConfig {
        //versionCode cdvVersionCode ?: Integer.parseInt("" + privateHelpers.extractIntFromManifest("versionCode") + "0")
        versionCode  Integer.parseInt("" + privateHelpers.extractIntFromManifest("versionCode"))
        applicationId privateHelpers.extractStringFromManifest("package")

        if (cdvMinSdkVersion != null) {
            minSdkVersion cdvMinSdkVersion
        }
    }

    //////////////////////////////////////////////////////////////////////////////////////////////////////////



    buildTypes {
        release {
            signingConfig signingConfigs.release
        }
    }

    //////////////////////////////////////////////////////////////////////////////////////////////////////////

    lintOptions {
        abortOnError false;
        disable "ResourceType"
    }

    compileSdkVersion cdvCompileSdkVersion
    buildToolsVersion cdvBuildToolsVersion

    if (Boolean.valueOf(cdvBuildMultipleApks)) {
        productFlavors {
            armv7 {
                //versionCode defaultConfig.versionCode + 2
                ndk {
                    abiFilters "armeabi-v7a", ""
                }
            }
            x86 {
                //versionCode defaultConfig.versionCode + 4
                ndk {
                    abiFilters "x86", ""
                }
            }
            all {
                ndk {
                    abiFilters "all", ""
                }
            }
        }
    } else if (!cdvVersionCode) {
      def minSdkVersion = cdvMinSdkVersion ?: privateHelpers.extractIntFromManifest("minSdkVersion")
      // Vary versionCode by the two most common API levels:
      // 14 is ICS, which is the lowest API level for many apps.
      // 20 is Lollipop, which is the lowest API level for the updatable system webview.
      if (minSdkVersion >= 20) {
        //defaultConfig.versionCode += 9
      } else if (minSdkVersion >= 14) {
        //defaultConfig.versionCode += 8
      }
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_6
        targetCompatibility JavaVersion.VERSION_1_6
    }

   if (cdvReleaseSigningPropertiesFile) {
        signingConfigs {
            release {
                // These must be set or Gradle will complain (even if they are overridden).
                keyAlias = ""
                keyPassword = "__unset" // And these must be set to non-empty in order to have the signing step added to the task graph.
                storeFile = null
                storePassword = "__unset"
            }
        }
        buildTypes {
            release {
                signingConfig signingConfigs.release
            }
        }
        addSigningProps(cdvReleaseSigningPropertiesFile, signingConfigs.release)
    }
    if (cdvDebugSigningPropertiesFile) {
        addSigningProps(cdvDebugSigningPropertiesFile, signingConfigs.debug)
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')
    // SUB-PROJECT DEPENDENCIES START
    debugCompile project(path: "CordovaLib", configuration: "debug")
    releaseCompile project(path: "CordovaLib", configuration: "release")
    // SUB-PROJECT DEPENDENCIES END

    compile 'com.android.support:design:25.0.0'

}

def promptForReleaseKeyPassword() {
    if (!cdvReleaseSigningPropertiesFile) {
        return;
    }
    if ('__unset'.equals(android.signingConfigs.release.storePassword)) {
        android.signingConfigs.release.storePassword = privateHelpers.promptForPassword('Enter key store password: ')
    }
    if ('__unset'.equals(android.signingConfigs.release.keyPassword)) {
        android.signingConfigs.release.keyPassword = privateHelpers.promptForPassword('Enter key password: ');
    }
}

gradle.taskGraph.whenReady { taskGraph ->
    taskGraph.getAllTasks().each() { task ->
        if (task.name == 'validateReleaseSigning') {
            promptForReleaseKeyPassword()
        }
    }
}

def addSigningProps(propsFilePath, signingConfig) {
    def propsFile = file(propsFilePath)
    def props = new Properties()
    propsFile.withReader { reader ->
        props.load(reader)
    }

    def storeFile = new File(props.get('key.store') ?: privateHelpers.ensureValueExists(propsFilePath, props, 'storeFile'))
    if (!storeFile.isAbsolute()) {
        storeFile = RelativePath.parse(true, storeFile.toString()).getFile(propsFile.getParentFile())
    }
    if (!storeFile.exists()) {
        throw new FileNotFoundException('Keystore file does not exist: ' + storeFile.getAbsolutePath())
    }
    signingConfig.keyAlias = props.get('key.alias') ?: privateHelpers.ensureValueExists(propsFilePath, props, 'keyAlias')
    signingConfig.keyPassword = props.get('keyPassword', props.get('key.alias.password', signingConfig.keyPassword))
    signingConfig.storeFile = storeFile
    signingConfig.storePassword = props.get('storePassword', props.get('key.store.password', signingConfig.storePassword))
    def storeType = props.get('storeType', props.get('key.store.type', ''))
    if (!storeType) {
        def filename = storeFile.getName().toLowerCase();
        if (filename.endsWith('.p12') || filename.endsWith('.pfx')) {
            storeType = 'pkcs12'
        } else {
            storeType = signingConfig.storeType // "jks"
        }
    }
    signingConfig.storeType = storeType
}

for (def func : cdvPluginPostBuildExtras) {
    func()
}

// This can be defined within build-extras.gradle as:
//     ext.postBuildExtras = { ... code here ... }
if (hasProperty('postBuildExtras')) {
    postBuildExtras()
}

apply plugin: "com.google.gms.google-services" //FCM Config

allprojects {
    repositories {
        jcenter{ url "http://jcenter.bintray.com/" }
    }
}

Build.gradle(模块:CordovaLib)

buildscript {
    repositories {
        jcenter{ url "http://jcenter.bintray.com/" }
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:2.3.3'
    }

}

apply plugin: 'com.android.library'

ext {
    apply from: 'cordova.gradle'
    cdvCompileSdkVersion = privateHelpers.getProjectTarget()
    cdvBuildToolsVersion = privateHelpers.findLatestInstalledBuildTools()
}

android {
    compileSdkVersion cdvCompileSdkVersion
    buildToolsVersion cdvBuildToolsVersion
    publishNonDefault true

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_6
        targetCompatibility JavaVersion.VERSION_1_6
    }

    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
        }
    }
    buildToolsVersion '25.0.0'
}

grad了-wrapper.properties

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip

是它的混合应用程序。使用Cordova-android。

我试过在谷歌搜索任何东西,但找不到一个简单的演示android(Cordova android)项目,它使用最新的生物识别支持库。

好吧所以上面的链接是一个工作的演示Android应用程序。

只有一个问题困扰我:为什么我不能在build.gradle中添加这一行(或者我需要添加它的地方)或者我如何添加它以便我在AS中的当前项目开始使用Bio-metric API进行面部ID登录。依赖关系{implementation'instalx.biometric:biometric:1.0.0-alpha03'

注意:Bounty将授予那些将逐步提供解决方案的人员,该解决方案是如何在当前项目中集成生物识别支持API,该项目使用我的build-extra.gradle文件中显示的旧支持库。

android cordova androidx cordova-android
3个回答
1
投票

经过14天的奋斗,我终于让我3岁的代码正常工作了。

这里有详细的步骤,以防任何人寻找相同的事情。

  1. 所以我有一个Cordova android混合应用旧代码。使用Android studio 3.2。 Build gradle版本很老,2.8和gradle版本是3.3。
  2. 我首先将Android工作室升级到最新版本3.3.2
  3. 现在我决定将整个项目迁移到androidX。请记住它甚至不会让我使用以前版本的Android工作室,我不知道为什么。
  4. 当我点击Refactor - > Migrate to AndroidX时。一个弹出窗口出现了“升级gradle版本。所以现在我将gradle版本更新到4.10.1,如果我将它升级到5.2(我不知道为什么,我还是Android的新手),它仍然会给我错误。”同时更新建立gradle到3.3.2

5.我的build.gradle(模块:App)看起来像这样:

apply plugin: 'com.android.application'

buildscript {
    repositories {
        jcenter{ url "http://jcenter.bintray.com/" }
        google()
    }

    // Switch the Android Gradle plugin version requirement depending on the
    // installed version of Gradle. This dependency is documented at
    // http://tools.android.com/tech-docs/new-build-system/version-compatibility
    // and https://issues.apache.org/jira/browse/CB-8143
    dependencies {
        classpath 'com.android.tools.build:gradle:3.3.2'
        classpath "com.google.gms:google-services:3.0.0" //FCM Config

    }
   }
  1. 现在App正在同步,构建正常。我再次尝试了Refactor - >迁移到androidX。这次Android工作室开始重构代码并为我提供了70个代码更改建议。
  2. 这些代码更改主要是头文件更改,如:import“”。所以我打开了这个链接 - https://developer.android.com/jetpack/androidx/migrate并将每个import语句更改为相等的androidx语句。
  3. 复制粘贴所有更改后,我再次编译并同步代码。在3个资源和代码编译错误之后,我能够构建代码。整个过程耗时1.2小时。
  4. 最后我能够在build-extras.gradle(Module:app)中导入生物识别支持API,查看文件: dependencies { api 'androidx.appcompat:appcompat:1.0.2' api "com.squareup.picasso:picasso:2.4.0" api "com.google.android.material:material:1.1.0-alpha04" api "com.google.firebase:firebase-messaging:9.2.0" //FCM Config api 'com.rmtheis:tess-two:6.0.2' api 'com.github.bumptech.glide:glide:3.8.0' api 'androidx.legacy:legacy-support-v4:1.0.0' api "androidx.biometric:biometric:1.0.0-alpha03" } }
  5. 最后,我能够构建完整的代码并进行同步。很高兴终于做到了。现在我只需要使用生物识别API函数将其集成到我的代码中(注意这段代码是3年前编写的,并提供给我用于集成最新的生物识别API)。

是的,我需要像这样一步一步地回答。

还要感谢所有帮助过的人。


0
投票

您需要在根项目的build.gradle中定义存储库:

allprojects {
    repositories {
        google()
    }
}

这些版本是a)完全过时和b)不要将com.android.supportandroidx混合。并且您无法将Java依赖项添加到buildscript依赖项中,因为这会生成错误消息Could not find method implementation()

也许这个网站的read the manual,以提供程序员所期望的输入。只是因为你有一台Mac并没有将你排除在这些指导原则之外......这些原因确实存在。

请勿发布代码,数据,错误消息等图像。 - 将文本复制或输入问题。请保留使用图像绘制图表或演示渲染错误,这些内容无法通过文本准确描述。

我也可以简单地修复依赖项......但是我太懒了,不能从截图中输入。


0
投票

您正在使用Gradle插件不支持的implementation关键字(2.3.3)

你绝对可以把它添加到你的gradle你只需要使用compile而不是implementation compile "androidx.biometric:biometric:1.0.0-alpha03"

如果您想使用实现,则需要更新Gradle插件。这将允许您使用较新的Android工作室,但需要您将一些东西迁移到新的gradle。

© www.soinside.com 2019 - 2024. All rights reserved.