gpt4 book ai didi

android - 如何将外部库依赖项添加到我的库中?

转载 作者:太空狗 更新时间:2023-10-29 13:46:10 27 4
gpt4 key购买 nike

我用另一个外部库创建了一个库,因为它是依赖项,

例如:我在我的库中使用了 Picasso 来加载图像,如果我将它包含在我的示例项目中它工作正常,但是当我通过 jitpack 分发它时,jcentermaven,外部依赖项不包含在其中。

(即)我的库被导入,但是我的库所依赖的 Picasso 没有被包含,因此我遇到了一个崩溃,因为 ClassNotFoundException,没有找到类在路径上:DexPathList

当我将我的库作为对其他项目的依赖时出现错误

Caused by: android.view.InflateException: Binary XML file line #14: 
Binary
XML file line #14: Error inflating class com.rd.PageIndicatorView
Caused by: android.view.InflateException: Binary XML file line #14:
Error
inflating class com.rd.PageIndicatorView
E/AndroidRuntime: Caused by: java.lang.ClassNotFoundException:
Didn't find
class "com.rd.PageIndicatorView" on path: DexPathList

项目级build.gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}

allprojects {
repositories {
jcenter()
google()
}
}

task clean(type: Delete) {
delete rootProject.buildDir
}

库build.gradle(应用级build.gradle)

apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'
group = 'com.github.technolifestyle'

ext {
bintrayRepo = 'AutoImageFlipper'
bintrayName = 'AutoImageFlipper'

publishedGroupId = 'com.github.technolifestyle'
libraryName = 'AutoImageFlipper'
artifact = 'imageslider'

libraryDescription = 'A carousel like implementation for Android with many functionalities'

siteUrl = 'https://github.com/therealshabi/AutoImageFlipper/'
gitUrl = 'https://github.com/therealshabi/AutoImageFlipper.git'

libraryVersion = '1.5.3-beta.5'

developerId = 'therealshabi'
developerName = 'Shahbaz Hussain'
developerEmail = 'shahbaz.h96@gmail.com'

licenseName = 'The Apache Software License, Version 2.0'
licenseUrl = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
allLicenses = ["Apache-2.0"]
}

android {
compileSdkVersion 28
buildToolsVersion '28.0.3'

defaultConfig {
multiDexEnabled true
minSdkVersion 17
targetSdkVersion 28
versionCode 1
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
api fileTree(include: ['*.jar'], dir: 'libs')
implementation 'androidx.appcompat:appcompat:1.1.0-alpha01'
implementation 'com.romandanylyk:pageindicatorview:1.0.3@aar'
implementation 'com.squareup.picasso:picasso:2.71828'
implementation 'androidx.multidex:multidex:2.0.1'
testImplementation 'junit:junit:4.12'
}

apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/installv1.gradle'
apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/bintrayv1.gradle'

谁能帮我解决我哪里出错了?

最佳答案

Can anyone help me with where I am going wrong?

我想说,你没有错!

I used Picasso in my library for image loading, it works fine if I include that in my sample project, but when I distribute it through jitpack, jcenter or maven, the external dependencies do not get included it with.

基本上,以我的愚见,我想在两种情况下考虑这一点。

  • 新的.aar 格式库。

    这是设计和预期的库行为。这是因为,每个库尽可能只包含自己的源代码和资源,而不应该包含/打包其依赖的库,否则,你的库用户将出现类冲突问题、版本问题甚至资源问题如果你的库是 .aar 格式。而且,目前,aar 库不可能优雅地合并(也许你已经看到一些 gradle 插件来合并 AAR,但由于资源合并、 list 合并等问题,官方不支持它)。

  • 典型的.jar格式库

    如果您的依赖库是 .jar 格式,我想说,是的,将它包含到您的库中是可能的,并且可以优雅地管理。但是,这仍然需要一些解决方法。 IE。您需要解压缩那些相关的 .jar 文件并将它们与您自己的 java 类一起重新打包。这样,为了让您的库用户不存在“类冲突”问题,您最好使用混淆工具混淆那些依赖的库包/类,例如progurard 或 dexguard。

这是一个可能对您的案例有用的链接:https://stackoverflow.com/a/51131236/8034839

关于android - 如何将外部库依赖项添加到我的库中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53983985/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com