无法从Android的MaterialChipsInput实例化ChipsInput

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

我只是通过将MaterialChipsInput添加到我的gradle文件并构建项目来获得此错误:

/root/.gradle/caches/transforms-1/files-1.1/MaterialChipsInput-1.0.8.aar/9cf34e21c8b45d8b575032229b78596a/res/values/values.xml
Error:(3, 5) error: unknown tag <:string>.
Error:(3, 5) error: unknown tag <:string>.
Error:(3, 5) error: unknown tag <:string>.
Error:(3, 5) error: unknown tag <:string>.
Error:(3, 5) error: unknown tag <:string>.
Error:(3, 5) error: unknown tag <:string>.
Error:(3, 5) error: unknown tag <:string>.
Error:(3, 5) error: unknown tag <:string>.
Error:(3, 5) error: unknown tag <:string>.
Error:(3, 5) error: unknown tag <:string>.
Error:(3, 5) error: unknown tag <:string>.
Error:(3, 5) error: unknown tag <:string>.
Error:(3, 5) error: unknown tag <:string>.
Error:(3, 5) error: unknown tag <:string>.
Error:(3, 5) error: unknown tag <:string>.
Error:(3, 5) error: unknown tag <:string>.
Error:(3, 5) error: unknown tag <:string>.
Error:(3, 5) error: unknown tag <:string>.
Error:(3, 5) error: unknown tag <:string>.
Error:(3, 5) error: unknown tag <:string>.
/home/mago/Git Folders/PETProjetos/app/build/intermediates/incremental/mergeDebugResources/merged.dir/values/values.xml
Error:(12) unknown tag <:string>.
Error:(13) unknown tag <:string>.
Error:(14) unknown tag <:string>.
Error:(15) unknown tag <:string>.
Error:(16) unknown tag <:string>.
Error:(17) unknown tag <:string>.
Error:(18) unknown tag <:string>.
Error:(19) unknown tag <:string>.
Error:(20) unknown tag <:string>.
Error:(21) unknown tag <:string>.
Error:(22) unknown tag <:string>.
Error:(23) unknown tag <:string>.
Error:(24) unknown tag <:string>.
Error:(25) unknown tag <:string>.
Error:(26) unknown tag <:string>.
Error:(27) unknown tag <:string>.
Error:(28) unknown tag <:string>.
Error:(29) unknown tag <:string>.
Error:(30) unknown tag <:string>.
Error:(31) unknown tag <:string>.
Error:java.util.concurrent.ExecutionException: com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details
Error:Execution failed for task ':app:mergeDebugResources'.
> Error: java.util.concurrent.ExecutionException: com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details
Information:BUILD FAILED in 2s
Information:42 errors
Information:0 warnings
Information:See complete output in console

当我点击第一个错误时,它会将我发送到此文件:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <array name="letter_tile_colors">
        <item>#f16364</item>
        <item>#f58559</item>
        <item>#f9a43e</item>
        <item>#e4c62e</item>
        <item>#67bf74</item>
        <item>#59a2be</item>
        <item>#2093cd</item>
        <item>#ad62a7</item>
    </array>
    <color name="chips_opened_bg">#009688</color>
    <color name="colorAccent">?attr/colorAccent</color>
    <color name="colorChipViewBackground">#E0E0E0</color>
    <color name="colorCloseChip">#ababab</color>
    <color name="white_transparency">#b9ffffff</color>
    <declare-styleable name="ChipView"><attr format="string" name="label"/><attr format="color" name="labelColor"/><attr format="boolean" name="hasAvatarIcon"/><attr format="reference" name="avatarIcon"/><attr format="boolean" name="deletable"/><attr format="reference" name="deleteIcon"/><attr format="color" name="deleteIconColor"/><attr format="color" name="backgroundColor"/></declare-styleable>
    <declare-styleable name="ChipsInput"><attr format="string" name="hint"/><attr format="color" name="hintColor"/><attr format="color" name="textColor"/><attr format="integer" name="maxRows"/><attr format="color" name="chip_labelColor"/><attr format="boolean" name="chip_hasAvatarIcon"/><attr format="boolean" name="chip_deletable"/><attr format="reference" name="chip_deleteIcon"/><attr format="color" name="chip_deleteIconColor"/><attr format="color" name="chip_backgroundColor"/><attr format="boolean" name="showChipDetailed"/><attr format="color" name="chip_detailed_textColor"/><attr format="color" name="chip_detailed_backgroundColor"/><attr format="color" name="chip_detailed_deleteIconColor"/><attr format="color" name="filterable_list_backgroundColor"/><attr format="color" name="filterable_list_textColor"/></declare-styleable>
    <declare-styleable name="ScrollViewMaxHeight"><attr format="dimension" name="maxHeight"/></declare-styleable>
    <dimen name="letter_tile_size">32dp</dimen>
    <dimen name="tile_letter_font_size">17sp</dimen>
    <string name="app_name">MaterialChipsInput</string>
</resources>

以及在构建目录中自动生成的另一个不应编辑的文件。

我已将compile: 'com.github.pchmn:MaterialChipsInput:1.0.8'添加到我的依赖项应用程序gradle文件中,并将maven { url "https://jitpack.io" }添加到我的项目gradle文件中。

当我将一个ChipsInput元素添加到我的xml布局文件中时,就像在github example中一样,我得到了这个:

java.lang.ClassCastException: android.view.Context cannot be cast to android.app.Activity
    at com.pchmn.materialchips.ChipsInput.init(ChipsInput.java:147)
    at com.pchmn.materialchips.ChipsInput.<init>(ChipsInput.java:79)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at org.jetbrains.android.uipreview.ViewLoader.createNewInstance(ViewLoader.java:481)
    at org.jetbrains.android.uipreview.ViewLoader.loadClass(ViewLoader.java:264)
    at org.jetbrains.android.uipreview.ViewLoader.loadView(ViewLoader.java:222)
    at com.android.tools.idea.rendering.LayoutlibCallbackImpl.loadView(LayoutlibCallbackImpl.java:211)
    at android.view.BridgeInflater.loadCustomView(BridgeInflater.java:337)
    at android.view.BridgeInflater.loadCustomView(BridgeInflater.java:348)
    at android.view.BridgeInflater.createViewFromTag(BridgeInflater.java:248)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
    at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:863)
    at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:72)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:837)
    at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
    at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:866)
    at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:72)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:837)
    at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
    at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:866)
    at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:72)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:837)
    at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:394)
    at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:325)
    at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:384)
    at com.android.tools.idea.layoutlib.LayoutLibrary.createSession(LayoutLibrary.java:193)
    at com.android.tools.idea.rendering.RenderTask.createRenderSession(RenderTask.java:547)
    at com.android.tools.idea.rendering.RenderTask.lambda$inflate$3(RenderTask.java:681)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)

我的项目在这里:https://github.com/o-mago/PETProjetos

android android-library build-error android-chips
1个回答
0
投票

其实我已经找到了解决方案。有两个问题:第一个是我用字符串而不是项目制作字符串数组。但主要问题是图书馆需要minSdkVersion为15,而我的是14.现在它正在工作。

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