发布版本的应用程序无法正常工作

时间:2017-02-17 19:18:07

标签: android firebase

我的android项目有问题。它似乎在调试模式下运行良好,但在发布模式下崩溃。我在我的项目中使用了firebase和google-account注册。当我在注册后尝试从数据库获取数据时,应用程序崩溃了。我在我的firebase控制台中添加了发布密钥的SHA-1和SHA-256指纹,并在我的项目中更改了google-services.json文件。我无法理解我做错了什么。错误:

java.lang.RuntimeException: java.lang.NoSuchMethodException: <init> [class android.view.View]
                                                   at com.firebase.ui.database.FirebaseRecyclerAdapter.onCreateViewHolder(FirebaseRecyclerAdapter.java:165)
                                                   at android.support.v7.widget.RecyclerView$Adapter.createViewHolder(RecyclerView.java:6319)
                                                   at android.support.v7.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:5507)
                                                   at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5392)
                                                   at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5388)
                                                   at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:2149)
                                                   at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1533)
                                                   at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1496)
                                                   at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:593)
                                                   at android.support.v7.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3535)
                                                   at android.support.v7.widget.RecyclerView.onMeasure(RecyclerView.java:2979)
                                                   at android.view.View.measure(View.java:17637)
                                                   at android.widget.RelativeLayout.measureChild(RelativeLayout.java:698)
                                                   at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:482)
                                                   at android.view.View.measure(View.java:17637)
                                                   at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5536)
                                                   at android.widget.FrameLayout.onMeasure(FrameLayout.java:436)
                                                   at android.view.View.measure(View.java:17637)
                                                   at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5536)
                                                   at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1436)
                                                   at android.widget.LinearLayout.measureVertical(LinearLayout.java:722)
                                                   at android.widget.LinearLayout.onMeasure(LinearLayout.java:613)
                                                   at android.view.View.measure(View.java:17637)
                                                   at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5536)
                                                   at android.widget.FrameLayout.onMeasure(FrameLayout.java:436)
                                                   at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2618)
                                                   at android.view.View.measure(View.java:17637)
                                                   at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2019)
                                                   at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1152)
                                                   at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1383)
                                                   at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1065)
                                                   at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5901)
                                                   at android.view.Choreographer$CallbackRecord.run(Choreographer.java:767)
                                                   at android.view.Choreographer.doCallbacks(Choreographer.java:580)
                                                   at android.view.Choreographer.doFrame(Choreographer.java:550)
                                                   at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:753)
                                                   at android.os.Handler.handleCallback(Handler.java:739)
                                                   at android.os.Handler.dispatchMessage(Handler.java:95)
                                                   at android.os.Looper.loop(Looper.java:211)
                                                   at android.app.ActivityThread.main(ActivityThread.java:5389)
                                                   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:1020)
                                                   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:815)
                                                Caused by: java.lang.NoSuchMethodException: <init> [class android.view.View]
                                                   at java.lang.Class.getConstructor(Class.java:531)
                                                   at java.lang.Class.getConstructor(Class.java:495)
                                                   at com.firebase.ui.database.FirebaseRecyclerAdapter.onCreateViewHolder(FirebaseRecyclerAdapter.java:162)
                                                   at android.support.v7.widget.RecyclerView$Adapter.createViewHolder(RecyclerView.java:6319) 
                                                   at android.support.v7.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:5507) 
                                                   at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5392) 
                                                   at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5388) 
                                                   at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:2149) 
                                                   at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1533) 
                                                   at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1496) 
                                                   at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:593) 
                                                   at android.support.v7.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3535) 
                                                   at android.support.v7.widget.RecyclerView.onMeasure(RecyclerView.java:2979) 
                                                   at android.view.View.measure(View.java:17637) 
                                                   at android.widget.RelativeLayout.measureChild(RelativeLayout.java:698) 
                                                   at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:482) 
                                                   at android.view.View.measure(View.java:17637) 
                                                   at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5536) 
                                                   at android.widget.FrameLayout.onMeasure(FrameLayout.java:436) 
                                                   at android.view.View.measure(View.java:17637) 
                                                   at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5536) 
                                                   at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1436) 
                                                   at android.widget.LinearLayout.measureVertical(LinearLayout.java:722) 
                                                   at android.widget.LinearLayout.onMeasure(LinearLayout.java:613) 
                                                   at android.view.View.measure(View.java:17637) 
                                                   at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5536) 
                                                   at android.widget.FrameLayout.onMeasure(FrameLayout.java:436) 
                                                   at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2618) 
                                                   at android.view.View.measure(View.java:17637) 
                                                   at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2019) 
                                                   at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1152) 
                                                   at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1383) 
                                                   at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1065) 
                                                   at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5901) 
                                                   at android.view.Choreographer$CallbackRecord.run(Choreographer.java:767) 
                                                   at android.view.Choreographer.doCallbacks(Choreographer.java:580) 
                                                   at android.view.Choreographer.doFrame(Choreographer.java:550) 
                                                   at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:753) 
                                                   at android.os.Handler.handleCallback(Handler.java:739) 
                                                   at android.os.Handler.dispatchMessage(Handler.java:95) 
                                                   at android.os.Looper.loop(Looper.java:211) 
                                                   at android.app.ActivityThread.main(ActivityThread.java:5389) 
                                                   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:1020) 
                                                   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:815) 

我也在我的项目中使用customview - de.hdodenhof.circleimageview.CircleImageView

public class GroupAdapter extends RecyclerView.Adapter<GroupAdapter.MyViewHolderGroup> {

private List<GroupItem> mGroupItems;

public static class MyViewHolderGroup extends RecyclerView.ViewHolder{
    TextView group_name;
    LinearLayout mLayout;
    MyViewHolderGroup(View view) {
        super(view);
        group_name = (TextView) view.findViewById(R.id.group_card_text);
        mLayout = (LinearLayout)view.findViewById(R.id.field_of_push);
    }
}
public GroupAdapter(List<GroupItem> groupList) {
    this.mGroupItems = groupList;
}
@Override
public GroupAdapter.MyViewHolderGroup onCreateViewHolder(ViewGroup parent, int viewType) {
    View itemView = LayoutInflater.from(parent.getContext())
            .inflate(R.layout.group_card, parent, false);
    return new GroupAdapter.MyViewHolderGroup(itemView);
}
@Override
public void onBindViewHolder(final GroupAdapter.MyViewHolderGroup holder, int position) {
    GroupItem group = mGroupItems.get(position);
    holder.group_name.setText(group.getGroupname());
}
@Override
public int getItemCount() {
    return mGroupItems.size();
}
}

的build.gradle

apply plugin: 'com.android.application'

android {
compileSdkVersion 25
buildToolsVersion "23.0.3"
defaultConfig {
    applicationId "com.example.nix.cathedraist"
    minSdkVersion 16
    targetSdkVersion 25
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    multiDexEnabled true
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
    exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.1.1'
compile 'com.android.support:design:25.1.1'
compile 'com.android.support:recyclerview-v7:25.1.1'
compile 'com.google.firebase:firebase-database:10.2.0'
compile 'com.firebaseui:firebase-ui-database:0.4.0'
compile 'com.google.firebase:firebase-auth:10.2.0'
compile 'com.google.android.gms:play-services-auth:10.2.0'
compile 'de.hdodenhof:circleimageview:2.1.0'
compile 'com.github.bumptech.glide:glide:3.7.0'
compile 'com.android.support:multidex:1.0.1'
testCompile 'junit:junit:4.12'
}
apply plugin: 'com.google.gms.google-services'

1 个答案:

答案 0 :(得分:1)

Probable causes

  

这可能有两个原因:

     
      
  1. 确保您的ViewHolder类是公开的
  2.   
  3. 如果您的ViewHolder是例如你的活动,确保它是静止的
  4.   

And a little more

  

如果嵌入它们,ViewHolder(和POJO类)只需要是静态的   进入另一个班级。

     

对于内部类,Java编译器生成一个隐藏字段(和   采用该字段的构造函数)以保持对包含的引用   对象,以便您可以在实例中执行MainActivity.this之类的操作   内在的阶级。这个隐藏的字段/参数使得它很难   Firebase / FirebaseUI中的反射代码,用于查找正确的构造函数。

     

将类标记为静态会删除隐式字段/参数,所以事情   再次正常工作。或者你可以放置CommentViewHolder   在它自己的文件CommentViewHolder.java。

更新:抱歉,我错过了问题的发布/调试部分。可能原因是混淆(proguard)。保持ViewHolder类。

更新2 :ViewHolder构造函数也应公开 FirebaseRecyclerAdapter Give NoSuchMethodException If Build using Release Keystore