-3

I am trying to create a telegram bot in form of an android application, the goal is: when i start the application, the bot would be responsive to its users on the internet!

but when I add the telegrambots-3.4-jar-with-dependencies.jar to app dependencies, the build comes up with the following warning and errors:

Information:Gradle tasks [:app:assembleDebug]
Warning:Ignoring InnerClasses attribute for an anonymous inner class
Error:com.android.builder.dexing.DexArchiveBuilderException: Failed to process C:\Users\user1\Documents\AndroidPj\appBot\app\libs\telegrambots-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:\Users\user1\Documents\AndroidPj\appBot\app\libs\telegrambots-3.4-jar-with-dependencies.jar
Information:BUILD FAILED in 34s
Information:4 errors
Information:1 warning
Information:See complete output in console

the mentioned jar file, is the telegram Bot API!

this is my build.gradle [module:app]

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')
}
omidXxX
  • 147
  • 1
  • 1
  • 9
  • i used the same jar file to create a java bot using netbeans! and it worked there! and the bot was responsive to interactions. – omidXxX Jan 16 '18 at 13:43
  • but i need a bot than i can run it on my android device, when ever i wanted to! because i don't have access to my laptop every where! and i dont want to use servers either! – omidXxX Jan 16 '18 at 13:47
  • You should ask author. – Sean Wei Jan 16 '18 at 13:48
  • what do you mean! who is the author? – omidXxX Jan 16 '18 at 13:48
  • do a research about this error ... it's obviously about incomatible java sdk versions used to compile library(1.8) and used to build android app(1.7) ... obvious solutions: 1. set minimal sdk to 26 as per error hint or 2. recompile library with older sdk if possible – Selvin Jan 16 '18 at 13:49
  • 1
    is it possible that [telegrambots-3.4-jar-with-dependencies.jar ] is not supposed to be used in android apps. and only can be used in java applications?? – omidXxX Jan 16 '18 at 13:55
  • if possible share your build.gradle... – DCoder Jan 16 '18 at 14:04

2 Answers2

1

try adding dependency through gradle dependency.

in your build.gradle add following lines.

dependencies {
compile 'com.github.pengrad:java-telegram-bot-api:3.5.2'
}
DCoder
  • 3,486
  • 7
  • 36
  • 68
  • thank you! i think this may solve the problem... but what is the repository url which i need to add, to get this dependency? – omidXxX Jan 16 '18 at 14:11
  • you don't have to add any URL, Just sync the project after adding above lines. – DCoder Jan 16 '18 at 14:16
  • the gradle says: Could not resolve com.github.pengrad:java-telegram-bot-api:3.5.2. – omidXxX Jan 16 '18 at 14:16
  • OK! my fault! i had wrong proxy configuration! now gradle downloaded the dependency! thank you again – omidXxX Jan 16 '18 at 14:53
  • you solved it! thank you! although this API has different internal architecture! and i need to learn it as well! – omidXxX Jan 16 '18 at 15:42
  • Problem still remains, but its from one of transitive dependencies of telegram-bot-api-3.5.2.jar – omidXxX Jan 24 '18 at 11:05
  • Although it builds successfully but when I try to run the app, I get invokeDynamic error – omidXxX Jan 24 '18 at 11:06
0

It looks like, that you have forgotten to add the jar to your project dependencies.

Right click on the jar file you have just added and click on 'Add as library'. This will take care of adding compile files('libs/library_name.jar') in the build.gradle file.

For further information have a closer look to this StackOverflow Question.

Yvonne Marggraf
  • 398
  • 2
  • 5
  • 19