-1

Hello WorldAndroid Studio. 最小的 sdk API 是 16。我安装了在 API 21 上运行的虚拟设备,程序运行良好。我还尝试在装有 Android 6 手机的 Galaxy S5 上运行该程序,效果很好。

然后我连接了我的手机(带有 Jelly Bean 的 Galaxy S2)并尝试在手机上运行它。但是它只关闭了应用程序并关闭了显示的程序。

这是Android Studio显示的日志

这是 Module:app build.gradle 文件:

apply plugin: 'com.android.application'

    android {
        compileSdkVersion 24
        buildToolsVersion "21.1.2"
        defaultConfig {
        applicationId "magu.schwaderina"
        minSdkVersion 16
        targetSdkVersion 24
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        vectorDrawables.useSupportLibrary = true
        }
        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:24.0.0'
        compile 'com.android.support:support-v4:24.0.0'
        compile 'com.android.support:support-vector-drawable:24.0.0'
        testCompile 'junit:junit:4.12'
    }

整个项目目录可以在这里找到。如果我出错了,任何帮助将不胜感激。

编辑:我忘了提到我在 Ubuntu 14.4 上使用 Android Studio 2.2 Prev 5

4

2 回答 2

1

如果您使用 v1.5.0 或更低版本的 Gradle 插件,则需要在应用的 build.gradle 中添加以下代码:

android {
  defaultConfig {
    // Stops the Gradle plugin’s automatic rasterization of vectors
    generatedDensities = []
  }
  // Flag to tell aapt to keep the attribute ids around
  aaptOptions {
    additionalParameters "--no-version-vectors"
  }
}

https://medium.com/@chrisbanes/appcompat-v23-2-age-of-the-vectors-91cbafa87c88#.njl8u0f91

于 2016-07-16T06:18:19.800 回答
0

所有信息都在您的日志中,请仔细查看,并会发现您的问题(与 Vector Drawable 相关)。所有信息都在日志​​中调用(包括行号等),因此只需按照错误说明您遇到的问题。

从日志底部开始向上移动。根据以下消息,您将看到您包含的 Vector Drawable 存在问题:

java.lang.RuntimeException: Unable to start activity ComponentInfo{magu.schwaderina/magu.schwaderina.Main}: android.content.res.Resources$NotFoundException: File res/drawable/abc_ic_ab_back_material.xml from drawable resource ID #0x7f020013

然后,如果您进一步向上移动,您会发现其他有趣的花絮,包括:

E/VdcInflateDelegate: Exception while inflating <vector>
                  org.xmlpull.v1.XmlPullParserException: Binary XML file line #17<vector> tag requires viewportWidth > 0
                      at 
于 2016-07-16T14:37:00.553 回答