V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
fenjuly
V2EX  ›  程序员

andriud studio 用 gradle 加入第三方 library 后编译没问题,在机器上测试报 java.lang.NoClassDefFoundError

  •  
  •   fenjuly ·
    fenjuly · 2014-09-12 23:40:08 +08:00 · 10866 次点击
    这是一个创建于 3731 天前的主题,其中的信息可能已经有所发展或是发生改变。
    我看到遇到相同问题的解决办法是在项目根目录运行./gradlew clean 我尝试了但是错误依然在

    希望各位能帮忙看一下,非常感谢!

    dependencies {
    compile "com.daimajia.swipelayout:library:1.0.9@aar"
    }

    我的代码:MainActivity.java

    public class MyActivity extends Activity {


    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_my);
    SwipeLayout swipeLayout = (SwipeLayout) findViewById(R.id.sample1);

    //set show mode.
    swipeLayout.setShowMode(SwipeLayout.ShowMode.LayDown);

    //set drag edge.
    swipeLayout.setDragEdge(SwipeLayout.DragEdge.Left);

    swipeLayout.addSwipeListener(new SwipeLayout.SwipeListener() {
    @Override
    public void onClose(SwipeLayout layout) {
    //when the SurfaceView totally cover the BottomView.
    }

    @Override
    public void onUpdate(SwipeLayout layout, int leftOffset, int topOffset) {
    //you are swiping.
    }

    @Override
    public void onOpen(SwipeLayout layout) {
    //when the BottomView totally show.
    }

    @Override
    public void onHandRelease(SwipeLayout layout, float xvel, float yvel) {
    //when user's hand released.
    }
    });
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.my, 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();
    if (id == R.id.action_settings) {
    return true;
    }
    return super.onOptionsItemSelected(item);
    }
    }

    activity_my.xml

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    tools:context=".MyActivity">

    <com.daimajia.swipe.SwipeLayout
    android:layout_width="match_parent" android:layout_height="80dp"
    android:id="@+id/sample1"
    >
    <!-- Bottom View Start-->
    <LinearLayout
    android:background="#66ddff00"
    android:id="@+id/bottom_wrapper"
    android:layout_width="160dp"
    android:weightSum="1"
    android:layout_height="match_parent"
    android:orientation="horizontal"
    >
    <!--What you want to show-->
    </LinearLayout>
    <!-- Bottom View End-->

    <!-- Surface View Start -->
    <LinearLayout
    android:padding="10dp"
    android:background="#ffffff"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <!--What you want to show in SurfaceView-->
    </LinearLayout>
    <!-- Surface View End -->
    </com.daimajia.swipe.SwipeLayout>

    </RelativeLayout>
    5 条回复    2014-09-13 23:20:39 +08:00
    dupengtao
        1
    dupengtao  
       2014-09-13 00:26:20 +08:00 via Android
    确定组件下载下来了?repositories写好了?
    fenjuly
        2
    fenjuly  
    OP
       2014-09-13 01:23:35 +08:00
    @dupengtao 嗯,编译都通过了
    inferjay
        3
    inferjay  
       2014-09-13 14:19:09 +08:00   ❤️ 1
    是否开启了混淆?如果开启了混淆,需要在proguard-android.txt中配置混淆规则,忽略第三方libray的规则:
    -dontwarn com.daimajia.swipe.**
    -keep class com.daimajia.swipe.**{*;}
    有木有更详细的错误日志?
    fenjuly
        4
    fenjuly  
    OP
       2014-09-13 17:06:48 +08:00
    @inferjay 你好,谢谢你的回答,不过我关闭了混淆的runProguard false。 下面是我的详细错误日志
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.liurongchan.myapplication/com.example.liurongchan.myapplication.MyActivity}: android.view.InflateException: Binary XML file line #11: Error inflating class com.daimajia.swipe.SwipeLayout
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
    at android.app.ActivityThread.access$600(ActivityThread.java:141)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:5103)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:525)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
    at dalvik.system.NativeStart.main(Native Method)
    Caused by: android.view.InflateException: Binary XML file line #11: Error inflating class com.daimajia.swipe.SwipeLayout
    at android.view.LayoutInflater.createView(LayoutInflater.java:620)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:267)
    at android.app.Activity.setContentView(Activity.java:1895)
    at com.example.liurongchan.myapplication.MyActivity.onCreate(MyActivity.java:17)
    at android.app.Activity.performCreate(Activity.java:5133)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
                at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
                at android.app.ActivityThread.access$600(ActivityThread.java:141)
                at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
                at android.os.Handler.dispatchMessage(Handler.java:99)
                at android.os.Looper.loop(Looper.java:137)
                at android.app.ActivityThread.main(ActivityThread.java:5103)
                at java.lang.reflect.Method.invokeNative(Native Method)
                at java.lang.reflect.Method.invoke(Method.java:525)
                at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
                at dalvik.system.NativeStart.main(Native Method)
    Caused by: java.lang.reflect.InvocationTargetException
    at java.lang.reflect.Constructor.constructNative(Native Method)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
    at android.view.LayoutInflater.createView(LayoutInflater.java:594)
                at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)
                at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
                at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
                at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
                at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
                at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:267)
                at android.app.Activity.setContentView(Activity.java:1895)
                at com.example.liurongchan.myapplication.MyActivity.onCreate(MyActivity.java:17)
                at android.app.Activity.performCreate(Activity.java:5133)
                at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
                at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
                at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
                at android.app.ActivityThread.access$600(ActivityThread.java:141)
                at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
                at android.os.Handler.dispatchMessage(Handler.java:99)
                at android.os.Looper.loop(Looper.java:137)
                at android.app.ActivityThread.main(ActivityThread.java:5103)
                at java.lang.reflect.Method.invokeNative(Native Method)
                at java.lang.reflect.Method.invoke(Method.java:525)
                at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
                at dalvik.system.NativeStart.main(Native Method)
    Caused by: java.lang.NoClassDefFoundError: com.daimajia.swipe.SwipeLayout$1
    at com.daimajia.swipe.SwipeLayout.<init>(SwipeLayout.java:162)
    at com.daimajia.swipe.SwipeLayout.<init>(SwipeLayout.java:52)
                at java.lang.reflect.Constructor.constructNative(Native Method)
                at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
                at android.view.LayoutInflater.createView(LayoutInflater.java:594)
                at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)
                at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
                at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
                at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
                at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
                at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:267)
                at android.app.Activity.setContentView(Activity.java:1895)
                at com.example.liurongchan.myapplication.MyActivity.onCreate(MyActivity.java:17)
                at android.app.Activity.performCreate(Activity.java:5133)
                at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
                at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
                at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
                at android.app.ActivityThread.access$600(ActivityThread.java:141)
                at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
                at android.os.Handler.dispatchMessage(Handler.java:99)
                at android.os.Looper.loop(Looper.java:137)
                at android.app.ActivityThread.main(ActivityThread.java:5103)
                at java.lang.reflect.Method.invokeNative(Native Method)
                at java.lang.reflect.Method.invoke(Method.java:525)
                at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
                at dalvik.system.NativeStart.main(Native Method)
    fenjuly
        5
    fenjuly  
    OP
       2014-09-13 23:20:39 +08:00
    @inferjay 我已经找到问题了The problem is class not found, the missing class is in android support library. Just add the support library then solved. Clear?

    还是感谢你
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2850 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 06:13 · PVG 14:13 · LAX 22:13 · JFK 01:13
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.