Import asmack source to android studio,but run App failed

E/SmackConfiguration﹕ Could not determine Smack version

java.lang.NullPointerException

at java.io.Reader.(Reader.java:64)

at java.io.InputStreamReader.(InputStreamReader.java:122)

at java.io.InputStreamReader.(InputStreamReader.java:59)

at org.jivesoftware.smack.SmackConfiguration.(SmackConfiguration.java:102)

at org.jivesoftware.smack.ConnectionConfiguration.(ConnectionConfiguration.j ava:67)

I imported asmack source to android studio and use gradle to compile.

My App is a android app, my app depend on asmack for IM chat.

import successfully, compile successfully, but run app in android system, I got error stack above.

the resonse is BufferedReader reader = new BufferedReader(new InputStreamReader(FileUtils.getStreamForUrl(“classpath:org.jivesoftware.smack/v ersion”, null)));

can not read version file in package. I don’t know how to resolve it. Please help me!

PS: resource files are available absolutely.

04D465B3-75E8-4D0C-8F56-E672D1362D13.png

I fixed the problem. the reason is that all files of org.jivesoftware.smack and org.jivesoftware.smacx folders won’t be packaged when gradle build.

I added some code in build.gradle to fix it.

task preBuild(overwrite:true) {
    copy {
        from('src/main/java/org.jivesoftware.smack') {
            include "**"
        }
        into('build/intermediates/classes/debug/org.jivesoftware.smack')
    }
    copy {
        from('src/main/java/org.jivesoftware.smack') {
            include "**"
        }
        into('build/intermediates/classes/release/org.jivesoftware.smack')
    }     copy {
        from('src/main/java/org.jivesoftware.smackx') {
            include "**"
        }
        into('build/intermediates/classes/debug/org.jivesoftware.smackx')
    }
    copy {
        from('src/main/java/org.jivesoftware.smackx') {
            include "**"
        }
        into('build/intermediates/classes/release/org.jivesoftware.smackx')
    }
}

Why did you import the source instead of the aSmack jar?

sorry, made a perplexing to you, this is just because I wanna debug easily, I am learning how smack works.

While I welcome this goal, I believe Android Studio does now support debugging with source attachments (at least that’s what I was told, since I don’t use AS I did not verify), therefore I would not suggest manually adding the source. Instead configure Smack 4.1’s maven artifacts. Then either tell gradle to attach the sources, or manually add them. And you may want to use Smack 4.1. But I would recommend studying 4.1 anyways, as many things have changed from 4.0.

1 Like

Thanks for your suggestion,I will do this

Also, consider not using Android when playing around and studying Smack. Instead use a standard java project. The Android specific code of Smack is only a few LOCs compared to the rest, so it’s best to get rid of that layer. It also has the advantage that you can debug/study using a standard JVM and don’t have to use an real Android device or Emulator.

You may want to try Flowdalic/smack-examples · GitHub , setting the project up in eclipse is as easy as “gradle eclipse” + “eclipse: import project”. From there you can use an debugger to set breakpoints and step through the code.

1 Like

thanks for your advanced suggestion again

I added the prebuild code to build.gradle file but nothing changed. should i place the code in a specific area inside the file?