【问题标题】:Android Bootstrap and Android studio cannot add libraryAndroid Bootstrap 和 Android studio 无法添加库
【发布时间】:2014-01-30 19:29:27
【问题描述】:

我想使用 Android Studio 将Android Bootstrap library 添加到我的项目中(我关注了this tutorial)。

我在项目资源管理器中看到了 Android Bootstrap 和我的项目,但如果我尝试添加引导按钮

 <!-- basic button -->
    <com.beardedhen.androidbootstrap.BootstrapButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        android:text="Success"
        bootstrapbutton:bb_icon_right="fa-android"
        bootstrapbutton:bb_type="success"
        />

我收到以下错误消息:

android-apt-compiler: layout/activity_main.xml:56: error: No resource identifier found for attribute 'bb_icon_right' in package 'com.carfinder'

我做错了什么?

【问题讨论】:

    标签: android android-studio android-activity android-bootstrap-widgets


    【解决方案1】:

    以防万一有人试图添加这个库并遇到这个问题但有不同的问题,我认为值得一提的是对我有用的完整步骤(我从another library 改编了维基):

    1. 在 Android Studio 中打开您的项目
    2. 下载库(使用 Git 或 zip 存档解压缩)
    3. 转到解压缩库的文件夹 > AndroidBootstrap > build.gradle
    4. 删除“应用自:'push.gradle'
    5. Integer.parseInt(TARGET_SDK_INT), Integer.parseInt(MIN_SDK_INT), Integer.parseInt(VERSION_CODE), VERSION_NAME, "25.0.1" 替换为您项目中的版本。您可以在 Gradle Scripts > build.gradle 中找到它们
    6. 转到文件 > 导入模块并导入库(您只需要 AndroidBootstrap 文件夹,而不是分支中的整个代码)
    7. 转到文件>项目结构
    8. 找到您的主要项目模块,单击它。 (您还应该在其下方看到 AndroidBootstrap)
    9. 单击它并转到依赖项。
    10. 点击左侧绿色“+”按钮>模块依赖
    11. 选择“AndroidBoostrap”

    现在一切都应该正常了。

    当您尝试从 AndroidBoostrap 库中添加元素时,您的 .xml 文件中可能仍会出现错误“命名空间‘应用程序’未绑定。”。您可以通过在 Android Studio 中单击 ALT + ENTER 来解决此错误,或添加此行

    xmlns:app="http://schemas.android.com/apk/res-auto"
    

    在声明或您的 Layout 和 xmlns:tools 之后,例如

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    

    我不知道这是否是关于如何包含库的最准确解决方案,因为我是 Android 初学者,但它对我有用。

    【讨论】:

      【解决方案2】:

      更新:

      确保你的项目结构应该是这样的,你的库可以在某个目录中,比如库>AndroidBootStrapLibrary 没问题,在这种情况下你只需要更改 settings.gradle 和 build.gradle 中的路径

          ----YOUR_PROJECT
             ---AndroidBootStrapLibrary
               --res
               --src
               -- .....
               -- build.gradle(must contain apply plugin: 'android-library' 
                  if not that menas not library project you have added something wrong)
             ---YOUR_MODULE
               --res
               --src
               --build.gradle (no : A)
         ----settings.gradle
      

      build.gradle(A号)文件

        dependencies {
             compile 'com.android.support:appcompat-v7:+'
             compile 'com.android.support:support-v4:18.0.+'
             compile project(':AndroidBootStrapLibrary')
        }
      

      settings.gradle:

        include ':YOUR_MODULE'
        include ':AndroidBootStrapLibrary'
      

      毕竟要与 Gradle 同步项目

      您忘记为库中的自定义视图添加命名空间。

      用这个替换你的按钮代码

           <com.beardedhen.androidbootstrap.BootstrapButton
               xmlns:bootstrapbutton="http://schemas.android.com/apk/res-auto"
               android:layout_width="wrap_content"
               android:layout_height="wrap_content"
               android:layout_margin="10dp"
               android:text="Success"
               bootstrapbutton:bb_icon_right="fa-android"
               bootstrapbutton:bb_type="success"
          />
      

      如果您正在使用,也可以在其他视图中添加命名空间。您也可以将其添加到布局文件的根元素中,例如

        <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
           xmlns:tools="http://schemas.android.com/tools"
           xmlns:bootstrapbutton="http://schemas.android.com/apk/res-auto"
           android:layout_width="match_parent"
           android:layout_height="match_parent"
           tools:context="com.example.app.MainActivity$PlaceholderFragment">
      
           <TextView
               android:text="@string/hello_world"
               android:layout_width="wrap_content"
               android:layout_height="wrap_content" />
      
           <com.beardedhen.androidbootstrap.BootstrapButton
               android:layout_width="wrap_content"
               android:layout_height="wrap_content"
               android:layout_margin="10dp"
               android:text="Success"
               bootstrapbutton:bb_icon_right="fa-android"
               bootstrapbutton:bb_type="success"
          />
      
        </RelativeLayout>
      

      我在这里上传了一个工作测试项目(在 AS 中的 Checkout form github)

      https://github.com/pyus-13/TesstApp.git

      【讨论】:

      • 不幸的是,这并没有解决问题。我得到了同样的错误信息。如果我尝试修复构建路径(检查 gen 和 andoid-support-v4 选项),我会收到消息。 Error running build: Module 'AndroidBootstrap' is not backed by gradle 也许这是导致问题的原因,但我不知道如何解决这个问题(我没有使用 Gradle 的经验)。
      • 它在我的项目中完美运行。请发布您的 ide 库屏幕截图以及 build.gradle 和 settings.gradle 文件。
      • 我已经在 Github github.com/pyus-13/TesstApp 上上传了我的测试项目@将它导入你的工作室并检查。
      • 您好,这里是截图postimg.org/image/cpvu1sqnp 我尝试在Android Studio 中通过gradle 向导添加android-bootstrap。它实现了比以前更多的项目,但是带有定义按钮的活动 xml 仍然显示错误。能否请您一步一步提供它的工作原理?
      • 抱歉没有找到你,如果你有任何其他问题,请将其放在单独的线程中。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-11
      • 1970-01-01
      • 1970-01-01
      • 2022-01-21
      • 1970-01-01
      相关资源
      最近更新 更多