Android Studio gradle 构建兼容 Android – 5.0 Lollipop 等

标签 android android-gradle-plugin

通过选择最低 Android 版本为 5.0 (Lollipop) 作为在 Android studio 中创建 Android 项目的一部分,我能够在 Android studio 中成功构建 APK 文件。

但是当我尝试在 Android 手机(5.0 版本)中安装 APK 时,出现包解析错误。

我还将 minifyEnabled 设置为 true

我注意到 Android studio 包含“compile 'com.android.support:appcompat-v7:24.2.0”,尽管我选择的最低版本是 Lollipop (5.0) 。 V24.2.0 适用于棉花糖。

任何专家都可以帮助我

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:theme="@style/AppTheme.NoActionBar">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

构建.gradle

在此处输入代码

   apply plugin: 'com.android.application'
  android {
compileSdkVersion 24
buildToolsVersion "24.0.1"
defaultConfig {
    applicationId "com.simpletest"
    minSdkVersion 21
    targetSdkVersion 24
    versionCode 1
    versionName "1.0"
    multiDexEnabled true
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}   
}
   dependencies {
     compile fileTree(dir: 'libs', include: ['*.jar'])
     testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:24.2.0'
   compile 'com.android.support:design:24.2.0'
    }

最佳答案

我在构建 Android 应用程序时遇到此错误

  1. 我对 build.gradle 文件进行了更改(将 24.2.0 更改为 23.0.0)或更改版本号。

    defaultConfig {
    applicationId "your package name"
    minSdkVersion 14
    targetSdkVersion 23
    versionCode 1
    versionName "1.0"
    }
       buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'),   'proguard-rules.pro'
    }
    }
     dexOptions {
     preDexLibraries = false
     javaMaxHeapSize "4g"
    }
    packagingOptions {
    exclude 'META-INF/LICENSE.txt'
    exclude 'META-INF/NOTICE.txt'
     }
      android {
      lintOptions {
        checkReleaseBuilds false
      }
     }
     defaultConfig {
      multiDexEnabled true
     }
     }
      dependencies {
         compile fileTree(dir: 'libs', include: ['*.jar'])
         testCompile 'junit:junit:4.12'
         compile 'com.android.support:appcompat-v7:23.0.0'
         compile 'com.android.support:design:23.0.0'
         }
    

关于Android Studio gradle 构建兼容 Android – 5.0 Lollipop 等,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39097807/

相关文章:

Android 自签名客户端 CA 证书认证失败

java - Android 原生守护进程通过 JNI 调用 Java 方法

android - 单击Android Studio中的更新Gradle后无法进行Cant Gradle同步-错误:Gradle 2.14.1需要Android Gradle插件2.1.3(或更高版本)

Android Studio 3.0 和 gradle 升级 - 创建 apk 时缺少 base.apk 代码

android - 从守护程序 : '...' is a result of a type we don't have a strategy to handle 收到无效响应

android - 在 Android Studio 中 Gradle 构建需要很长时间才能完成

android - 用 Handler 覆盖 onBackPressed 会导致 NPE

java - 如何使用 VisibleForTesting 进行纯 JUnit 测试

java - 在android上安装Java库[GIThub源代码]

Android gradle JAR 依赖项最终声明为 native