2015-08-08 73 views
0

我正在搜索將Android設備變成FTP服務器的庫。 似乎有無數的圖書館爲Java FTP客戶端,但是我看到了一個問題here.在Android應用程序中嵌入Apache FTP服務器

因此,進出口下面這個教程在這裏:

here.

但是運行我的應用程序給我一個NoClassDefFoundError的

MainActivity.java

public class MainActivity extends AppCompatActivity { 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 

     FtpServerFactory serverFactory = new FtpServerFactory(); 
     FtpServer server = serverFactory.createServer(); 
     // start the server 
     try { 
      server.start(); 
     } catch (FtpException e) { 
      e.printStackTrace(); 
     } 
    } 

    @Override 
    public boolean onCreateOptionsMenu(Menu menu) { 
     // Inflate the menu; this adds items to the action bar if it is present. 
     getMenuInflater().inflate(R.menu.menu_main, menu); 
     return true; 
    } 

    @Override 
    public boolean onOptionsItemSelected(MenuItem item) { 
     // Handle action bar item clicks here. The action bar will 
     // automatically handle clicks on the Home/Up button, so long 
     // as you specify a parent activity in AndroidManifest.xml. 
     int id = item.getItemId(); 

     //noinspection SimplifiableIfStatement 
     if (id == R.id.action_settings) { 
      return true; 
     } 

     return super.onOptionsItemSelected(item); 
    } 
} 

build.gradl Ë

apply plugin: 'com.android.application' 

android { 
    compileSdkVersion 22 
    buildToolsVersion "22.0.1" 

    defaultConfig { 
     applicationId "com.ken.androidftpserver" 
     minSdkVersion 15 
     targetSdkVersion 22 
     versionCode 1 
     versionName "1.0" 
    } 
    buildTypes { 
     release { 
      minifyEnabled false 
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
     } 
    } 

    packagingOptions { 
     exclude 'META-INF/DEPENDENCIES.txt' 
     exclude 'META-INF/LICENSE.txt' 
     exclude 'META-INF/NOTICE.txt' 
     exclude 'META-INF/NOTICE' 
     exclude 'META-INF/LICENSE' 
     exclude 'META-INF/DEPENDENCIES' 
     exclude 'META-INF/notice.txt' 
     exclude 'META-INF/license.txt' 
     exclude 'META-INF/dependencies.txt' 
     exclude 'META-INF/LGPL2.1' 
    } 
} 

的logcat:

java.lang.NoClassDefFoundError: Failed resolution of: Lorg/apache/mina/filter/executor/OrderedThreadPoolExecutor; 
     at org.apache.ftpserver.listener.nio.NioListener.<init>(NioListener.java:76) 
     at org.apache.ftpserver.listener.ListenerFactory.createListener(ListenerFactory.java:90) 
     at org.apache.ftpserver.impl.DefaultFtpServerContext.<init>(DefaultFtpServerContext.java:91) 
     at org.apache.ftpserver.FtpServerFactory.<init>(FtpServerFactory.java:51) 
     at com.ken.androidftpserver.MainActivity.onCreate(MainActivity.java:19) 
     at android.app.Activity.performCreate(Activity.java:5958) 
     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1129) 
     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2364) 
     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2474) 
     at android.app.ActivityThread.access$800(ActivityThread.java:144) 
     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1359) 
     at android.os.Handler.dispatchMessage(Handler.java:102) 
     at android.os.Looper.loop(Looper.java:155) 
     at android.app.ActivityThread.main(ActivityThread.java:5696) 
     at java.lang.reflect.Method.invoke(Native Method) 
     at java.lang.reflect.Method.invoke(Method.java:372) 
     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1028) 
     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:823) 
Caused by: java.lang.ClassNotFoundException: Didn't find class "org.apache.mina.filter.executor.OrderedThreadPoolExecutor" on path: DexPathList[[zip file "/data/app/com.ken.androidftpserver-1/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]] 
     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56) 
     at java.lang.ClassLoader.loadClass(ClassLoader.java:511) 
     at java.lang.ClassLoader.loadClass(ClassLoader.java:469) 
      at org.apache.ftpserver.listener.nio.NioListener.<init>(NioListener.java:76) 
      at org.apache.ftpserver.listener.ListenerFactory.createListener(ListenerFactory.java:90) 
      at org.apache.ftpserver.impl.DefaultFtpServerContext.<init>(DefaultFtpServerContext.java:91) 
      at org.apache.ftpserver.FtpServerFactory.<init>(FtpServerFactory.java:51) 
      at com.ken.androidftpserver.MainActivity.onCreate(MainActivity.java:19) 
      at android.app.Activity.performCreate(Activity.java:5958) 
      at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1129) 
      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2364) 
      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2474) 
      at android.app.ActivityThread.access$800(ActivityThread.java:144) 
      at  android.app.ActivityThread$H.handleMessage(ActivityThread.java:1359) 
      at android.os.Handler.dispatchMessage(Handler.java:102) 
      at android.os.Looper.loop(Looper.java:155) 
      at android.app.ActivityThread.main(ActivityThread.java:5696) 
      at java.lang.reflect.Method.invoke(Native Method) 
      at java.lang.reflect.Method.invoke(Method.java:372) 
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1028) 
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:823) 
Suppressed: java.lang.ClassNotFoundException: org.apache.mina.filter.executor.OrderedThreadPoolExecutor 
     at java.lang.Class.classForName(Native Method) 
     at java.lang.BootClassLoader.findClass(ClassLoader.java:781) 
     at java.lang.BootClassLoader.loadClass(ClassLoader.java:841) 
     at java.lang.ClassLoader.loadClass(ClassLoader.java:504) 
     ... 19 more 
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available 

是否有任何庫在那裏?

+0

您是否將Apache Mina jar放入您的Android項目的'libs'文件夾中? –

+0

是的,我做到了。米娜2.0.4 – silberbaum

回答

0

問題是我正在使用不同版本的slf4j-simple和slf4j。他們需要是一樣的。

相關問題