导入应用程序后无法使用arr文件中的依赖项 [英] Unable to use the dependencies in the arr file after importing in the application

查看:117
本文介绍了导入应用程序后无法使用arr文件中的依赖项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个使用recyclerview的库,然后将该库(即arr文件)导入到应用程序项目中.

I am trying to create a library, that uses recyclerview, and then importing that library ie., arr file to an application project.

我在库的gradle文件中所做的更改是

Changes i did in the library's gradle file are

  • 应用插件:"com.android.library"
  • 删除了 applicationId
  • 然后生成 aar 文件
  • apply plugin: 'com.android.library'
  • removed the applicationId
  • And then generated aar file

库的gradle文件具有依赖项列表

The library's gradle file has a list of dependencies

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:24.2.0'
compile 'com.android.volley:volley:1.0.0'
compile 'com.github.bumptech.glide:glide:3.7.0'
compile 'com.android.support:recyclerview-v7:24.2.0'

}

现在,我将aar文件导入了我的应用程序.当我尝试访问包含recyclerview的活动时,应用崩溃了以下错误...

Now i imported the aar file to my app. When i try to access the activity containing the recyclerview, the app crashes the following err...

FATAL EXCEPTION: main 
            Process: com.example.alertlibtest, PID: 32032
                    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.alertlibtest/com.example.example.tejlib.Jaamoon}: android.view.InflateException: Binary XML file line #11: Binary XML file line #11: Error inflating class android.support.v7.widget.RecyclerView
                    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
                    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
                    at android.app.ActivityThread.-wrap11(ActivityThread.java)
                    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
                    at android.os.Handler.dispatchMessage(Handler.java:102)
                    at android.os.Looper.loop(Looper.java:148)
                    at android.app.ActivityThread.main(ActivityThread.java:5417)
                    at java.lang.reflect.Method.invoke(Native Method)
                    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
                    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
                    Caused by: android.view.InflateException: Binary XML file line #11: Binary XML file line #11: Error inflating class android.support.v7.widget.RecyclerView
                    at android.view.LayoutInflater.inflate(LayoutInflater.java:539)
                    at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
                    at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
                    at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:284)
                    at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
                    at com.example.example.tejlib.Jaamoon.onCreate(Jaamoon.java:34)
                    at android.app.Activity.performCreate(Activity.java:6237)
                    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
                    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
                    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
                    at android.app.ActivityThread.-wrap11(ActivityThread.java) 
                    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
                    at android.os.Handler.dispatchMessage(Handler.java:102) 
                    at android.os.Looper.loop(Looper.java:148) 
                    at android.app.ActivityThread.main(ActivityThread.java:5417) 
                    at java.lang.reflect.Method.invoke(Native Method) 
                    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
                    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
                    Caused by: android.view.InflateException: Binary XML file line #11: Error inflating class android.support.v7.widget.RecyclerView
                    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:776)
                    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
                    at android.view.LayoutInflater.rInflate(LayoutInflater.java:835)
                    at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
                    at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
                    at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
                    at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
                    at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:284) 
                    at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) 
                    at com.example.example.tejlib.Jaamoon.onCreate(Jaamoon.java:34) 
                    at android.app.Activity.performCreate(Activity.java:6237) 
                    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107) 
                    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369) 
                    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
                    at android.app.ActivityThread.-wrap11(ActivityThread.java) 
                    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
                    at android.os.Handler.dispatchMessage(Handler.java:102) 
                    at android.os.Looper.loop(Looper.java:148) 
                    at android.app.ActivityThread.main(ActivityThread.java:5417) 
                    at java.lang.reflect.Method.invoke(Native Method) 
                    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
                    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
                    Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v7.widget.RecyclerView" on path: DexPathList[[zip file "/data/app/com.example.alertlibtest-1/base.apk"],nativeLibraryDirectories=[/data/app/com.example.alertlibtest-1/lib/x86, /vendor/lib, /system/lib]]
                    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
                    at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
                    at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
                    at android.view.LayoutInflater.createView(LayoutInflater.java:583)
                    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:764)
                    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704) 
                    at android.view.LayoutInflater.rInflate(LayoutInflater.java:835) 
                    at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) 
                    at android.view.LayoutInflater.inflate(LayoutInflater.java:515) 
                    at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
                    at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
                    at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:284) 
                    at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) 
                    at com.example.example.tejlib.Jaamoon.onCreate(Jaamoon.java:34) 
                    at android.app.Activity.performCreate(Activity.java:6237) 
                    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107) 
                    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369) 
                    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
                    at android.app.ActivityThread.-wrap11(ActivityThread.java) 
                    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
                    at android.os.Handler.dispatchMessage(Handler.java:102) 
                    at android.os.Looper.loop(Looper.java:148) 
                    at android.app.ActivityThread.main(ActivityThread.java:5417) 
                    at java.lang.reflect.Method.invoke(Native Method) 
                    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
                    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
                    Suppressed: java.lang.ClassNotFoundException: Didn't find class "android.support.v7.widget.RecyclerView" on path: DexPathList[[dex file "/data/data/com.example.alertlibtest/files/instant-run/dex/slice-support-annotations-24.2.0_28ab

请帮助摆脱该错误.我想访问我包含在库中的其他库,即 volley glide .

Please help to get rid of this error. I want to access the other libraries that i include in the library ie volley and glide.

谢谢.

推荐答案

如果要将库发布到工件存储库,则需要配置publish gradle命令以添加库具有的依赖项.在Bintray中,我是通过这种方式完成的

If you're publishing your library to an artifactory repository, you need to configure your publish gradle commands to add the dependencies your library has. In Bintray I do it in this way

artifacts {
    archives generateSourcesJar
}

task generateSourcesJar(type: Jar) {
    from android.sourceSets.main.java.srcDirs
    classifier 'sources'
}

然后,您只需要告诉gradle您正在使用库中包含的类.您可以通过这种方式完成

Then you only need to tell gradle that you're using the classes that your library contains. You can do it in this way

compile('com.yourpage:yourlibrary:1.0.0'){
    transitive=true
}

这篇关于导入应用程序后无法使用arr文件中的依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆