andriud studio 用 gradle 加入第三方 library 后编译没问题,在机器上测试报 java.lang.NoClassDefFoundError - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
请不要在回答技术问题时复制粘贴 AI 生成的内容
fenjuly
V2EX    程序员

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

  •  
  •   fenjuly
    fenjuly 2014-09-12 23:40:08 +08:00 11291 次点击
    这是一个创建于 4056 天前的主题,其中的信息可能已经有所发展或是发生改变。
    我看到遇到相同问题的解决办法是在项目根目录运行./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.LaoutInflater.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     Solana     1068 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 25ms UTC 22:59 PVG 06:59 LAX 15:59 JFK 18:59
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86