安装v7支持库时出错,以便我可以使用Toolbar类

时间:2015-09-24 01:40:23

标签: android android-support-library android-toolbar

今天我通过将以下行添加到build.gradle的依赖项部分,将v7支持库的rev 23.0.1安装到我的项目中:

import java.util.*;
public class test {

    public static void main(String[] args) {
        List<String> listOfStrings= new ArrayList<>();
        listOfStrings.add("abc");
        listOfStrings.add("def");
        listOfStrings.add("ghi");
        listOfStrings.add("jkl");
        listOfStrings.add("mno");

        show("\nInitial list:", listOfStrings);

        String singleString = listOfStrings.toString();

        show("As single string:", singleString);

        List<String> reconstitutedList = Arrays.asList(
             singleString.substring(0, singleString.length() - 1)
                  .substring(1).split("[\\s,]+"));

        show("Reconstituted list:", reconstitutedList);
    }

    public static void show(String title, Object operand) {
        System.out.println(title + "\n");
        if (operand instanceof String) {
            System.out.println("    \"" + operand + "\"");
        } else {
            for (String string : (List<String>)operand)
                System.out.println("    \"" + string + "\"");
        }
        System.out.println("\n");
    }
}

但是现在我收到了大量的错误:

compile "com.android.support:appcompat-v7:23.0.1"

...并以:

结束
AGPBI: {"kind":"ERROR","text":"Error retrieving parent for item: No resource found that matches the given name \u0027android:TextAppearance.Material\u0027.","sourcePath":"/myproject/build/intermediates/exploded-aar/com.android.support/appcompat-v7/23.0.1/res/values-v21/values-v21.xml","position":{"startLine":1},"original":""}

所以我尝试直接从setup instructions

复制/粘贴确切的行
Error:Execution failed for task ':MyApp:processDebugResources'.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/Users/fruitman/Library/Android/sdk/build-tools/build-tools-19.1.0/aapt'' finished with non-zero exit value 1

现在gradle同步有效,但compile "com.android.support:appcompat-v7:18.0.+" 尚未解析,恰好是我需要的类。 :(

有人知道如何安装正确版本的支持库,以便我可以使用支持工具栏吗?

提前致谢...

1 个答案:

答案 0 :(得分:0)

compile "com.android.support:appcompat-v7:23.0.1"放入您的gradle文件后,您还需要更新以下内容 -

android {
    compileSdkVersion 23
    buildToolsVersion "22.0.1"

    defaultConfig {
        applicationId "com.example.myapp"
        minSdkVersion 14
        targetSdkVersion 23
    }
}

这里可能会发生什么,AppCompat V7试图访问SDK版本23中存在的东西而且它们无法找到它们,因为你的compileSdkVersion可能低于23。