Question

I've been developing an App that uses FTP connection. In my first trials, and after lots (LOTS) of attempts, I could put the FTP to work (main problem was the libraries include). Now I developped the main frame of the App, and want to upload the data, and again, I can't include the library.

I'm using android studio, I have the libs folder, and the jar ins in there.

   buildscript {
       repositories {
           mavenCentral()
    }
       dependencies {
           classpath 'com.android.tools.build:gradle:0.6.+'
           compile files('libs/org.apache.commons.net.jar')
       }
   }

And in the class, I have the import statements

import org.apache.commons.net.ftp.FTP;
import org.apache.commons.net.ftp.FTPClient;

I've also added the jar as library within the project explorer, but I'm still getting a compile error:

Gradle: A problem occurred evaluating project ':Project_Name'.

No signature of method: org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.compile() is applicable for argument types: (org.gradle.api.internal.file.collections.DefaultConfigurableFileCollection) values: [file collection] Possible solutions: module(java.lang.Object)

I can't seem to get around this, I've tried many differents ways to import the library, and raided the net for a solution, but none seems to work, would appreciate your help.

Thanks in advance

PS:can someone point me to a good book/article regarding android application build process, as I would want to get really into it, so I don't have this pain-in-the-arse problems anymore.

EDIT1:

Logcat is giving me this, after sucessfully loading the library:

12-13 13:01:50.640  31172-31192/? E/AndroidRuntime﹕ FATAL EXCEPTION: Thread-6502
java.lang.NoClassDefFoundError: org/apache/commons/net/ftp/FTPClient
        at com.example.dev_gpsreport1.FTPConnection.run(FTPConnection.java:35)
        at java.lang.Thread.run(Thread.java:856)
 Caused by: java.lang.ClassNotFoundException: org.apache.commons.net.ftp.FTPClient
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:461)

            at com.example.dev_gpsreport1.FTPConnection.run(FTPConnection.java:35)             at java.lang.Thread.run(Thread.java:856)

The problem is I can see the declaration of the class.

Was it helpful?

Solution

Firstly : you've mixed up two things: the "dependency" configuration block within the "buildscript" and the main "dependency" configuration block.

Secondly: no need to copy external libs (commons.net) locally, gradle can download them for you, see section on external libs

So, you're probably looking for something like this:

apply plugin: 'android' // importing the "android" plugin for gradle

buildscript {
    repositories {
        mavenCentral()
    }
    /* 
     * dependencies for your buildscript
     * make sure your buildscript finds the "android" plugin 
     */
    dependencies {      
        classpath 'com.android.tools.build:gradle:0.6.+'
    }
}

/* (external) dependencies for your application */
dependencies {
   compile 'org.apache.ant:ant-commons-net:<your-version>'
}

Give it a try...

wrt documentation:

As a reference, you might also want to take a look at the samples available on the new Android build system page

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top