将电报 api jar 文件作为依赖项添加到 android prject 时,我收到调用动态不支持的错误



我正在尝试以 android 应用程序的形式创建一个电报机器人,目标是:当我启动应用程序时,机器人将响应互联网上的用户!

但是当我将 Telegrambots-3.4-jar-with-dependencies.jar 添加到应用程序依赖项时,构建会出现以下警告和错误:

Information:Gradle tasks [:app:assembleDebug]
Warning:Ignoring InnerClasses attribute for an anonymous inner class
Error:com.android.builder.dexing.DexArchiveBuilderException: Failed to process C:Usersuser1DocumentsAndroidPjappBotapplibstelegrambots-3.4-jar-with-dependencies.jar
Error:com.android.builder.dexing.DexArchiveBuilderException: Error while dexing org/telegram/telegrambots/generics/LongPollingBot.class
Error:com.android.dx.cf.code.SimException: invalid opcode ba (invokedynamic requires --min-sdk-version >= 26)
Error:Execution failed for task ':app:transformClassesWithDexBuilderForDebug'.
> com.android.build.api.transform.TransformException: com.android.builder.dexing.DexArchiveBuilderException: com.android.builder.dexing.DexArchiveBuilderException: Failed to process C:Usersuser1DocumentsAndroidPjappBotapplibstelegrambots-3.4-jar-with-dependencies.jar
Information:BUILD FAILED in 34s
Information:4 errors
Information:1 warning
Information:See complete output in console

提到的jar文件,是电报机器人API!

这是我的build.gradle [模块:应用程序]

apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId "oa.azadi.omidazadibot"
minSdkVersion 15
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
implementation files('libs/telegrambots-3.4-jar-with-dependencies.jar')
}

尝试通过 gradle 依赖项添加依赖项。

在你的build.gradle中添加以下行。

dependencies {
compile 'com.github.pengrad:java-telegram-bot-api:3.5.2'
}

看起来,您忘记将 jar 添加到项目依赖项中。

右键单击您刚刚添加的jar文件,然后单击"添加为库"。这将负责在build.gradle文件中添加编译文件('libs/library_name.jar')。

有关更多信息,请仔细查看此 StackOverflow 问题。

最新更新