Android 应用程序安装 API 24,但不会安装 API 19(Jack 工具链问题?)

Android App installs with API 24, but will not for API 19 (Jack toolchain issue?)

我对 android 开发有些陌生,所以我在为多个 API 开发时遇到了一些问题。当我创建我的项目时,我将最小 API 级别设置为 18,这甚至不再受支持(根据 wiki:https://en.wikipedia.org/wiki/Android_version_history

我在两部不同的手机上测试了一个 APK 的安装,都是 API 24,没有任何问题。但是,我与 API 19 的同事无法安装该应用程序。显然它给了他 "App not installed."

的信息错误

出于测试目的,我创建了一个新项目,没有添加任何代码(只留下 Android Studio 生成的 "Hello World" 标签),生成了一个签名的 APK,然后将其发送给我的同事.他也安装失败。

唯一值得注意的另一件事是我尝试启用 "jack." 我正在测试一些需要它的随机源代码。我想知道这是否会引起问题?很难相信一个空项目。

更具体地说,我在测试上面提到的源代码时出现了这个错误"Error:Jack is required to support java 8 language features. Either enable Jack or remove sourceCompatibility JavaVersion.VERSION_1_8."所以,我当然启用了Jack。

这是 build.gradle(如果有帮助?)

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.2"
    defaultConfig {
        applicationId "com.random.name"
        minSdkVersion 18
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:25.3.1'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    testCompile 'junit:junit:4.12'
}

非常感谢任何想法!

看起来您正在尝试在您的项目中使用 java 8,java 8 在 API 级别 18 上不起作用,您还需要为此启用 jack 工具链

来源:https://developer.android.com/guide/platform/j8-jack.html

不过如果您想使用 java 8 种功能,您可以将 retrolambda 与 gradle 结合使用 https://github.com/evant/gradle-retrolambda

目前,如果您不使用任何 java 8 功能,则只需将 gradle 文件中的源兼容性更改为 java 7 而不是 java 8它应该工作正常。

使用这个

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}

而不是

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

可以将其粘贴到您的 gradle 文件中,例如:

 android {
 ...
 defaultConfig {
 ...

 }
 compileOptions {
  sourceCompatibility JavaVersion.VERSION_1_8
  targetCompatibility JavaVersion.VERSION_1_8
 }
}