android.support.v4和android.support.v7在构建apk时出错

时间:2016-05-26 10:00:22

标签: android android-fragments android-support-library emoji

我正在使用android支持库。当我同步或清理项目没有错误发生时它很好,但是当我构建apk时,它给了我支持库方法的错误。

这是我的gradle文件

buildscript {
  repositories {
     jcenter() // or mavenCentral()
  }

 dependencies {
     classpath 'com.android.tools.build:gradle:2.1.0'
 }
}
 apply plugin: 'com.android.application'

android {
dexOptions {
    incremental = true;
    preDexLibraries = false
    javaMaxHeapSize "4g" // 2g should be also OK
}

compileSdkVersion 23
buildToolsVersion '23.0.2'

useLibrary 'org.apache.http.legacy'
lintOptions {
    checkReleaseBuilds false

}
defaultConfig {
    applicationId "xyz"
    minSdkVersion 19
    targetSdkVersion 20

    multiDexEnabled true
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'


    }
}
productFlavors {
}

}


dependencies {
compile project(':listViewLibrary')
compile 'com.google.code.gson:gson:2.2.4'
compile files('libs/AF-Android-SDK-v3.3.0.jar')
compile files('libs/android-query.0.26.7.jar')
compile files('libs/asmack-android-6-0.8.1.1.jar')
compile files('libs/PayPalAndroidSDK.jar')
compile files('libs/picasso-2.5.2.jar')
compile files('libs/volley.jar')
compile files('libs/gcm.jar')
compile project(':library')
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:recyclerview-v7:23.1.1'
compile 'de.hdodenhof:circleimageview:2.0.0'
compile 'com.facebook.android:facebook-android-sdk:4.10.0'
compile 'com.github.frank-zhu:pullzoomview:1.0.0'
compile 'com.google.android.gms:play-services-maps:8.4.0'
compile 'com.google.android.gms:play-services-analytics:8.4.0'
compile 'com.android.support:support-v4:23.1.1'
}
repositories {
jcenter()

}

这是错误

 /Users/Punit/Downloads/xyz/src/main/java/rockerhieu/emojicon/EmojiconGridFragment.java:94: error: cannot find symbol
    } else if (getParentFragment() instanceof OnEmojiconClickedListener) {
               ^
 symbol:   method getParentFragment()
 location: class EmojiconGridFragment

这是我收到错误的文件

  package rockerhieu.emojicon;

  import java.util.Arrays;

  import xyz.R;

  import rockerhieu.emojicon.emoji.Emojicon;
  import rockerhieu.emojicon.emoji.People;

  import android.app.Activity;
  import android.support.v4.app.Fragment;
  import android.os.Bundle;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.AdapterView;
  import android.widget.GridView;

  public class EmojiconGridFragment extends Fragment implements AdapterView.OnItemClickListener {
private OnEmojiconClickedListener mOnEmojiconClickedListener;
private EmojiconRecents mRecents;
private Emojicon[] mData;
private boolean mUseSystemDefault = false;

private static final String USE_SYSTEM_DEFAULT_KEY = "useSystemDefaults";

protected static EmojiconGridFragment newInstance(Emojicon[] emojicons, EmojiconRecents recents) {
    return newInstance(emojicons, recents, false);
}

protected static EmojiconGridFragment newInstance(Emojicon[] emojicons, EmojiconRecents recents, boolean useSystemDefault) {
    EmojiconGridFragment emojiGridFragment = new EmojiconGridFragment();
    Bundle args = new Bundle();
    args.putSerializable("emojicons", emojicons);
    args.putBoolean(USE_SYSTEM_DEFAULT_KEY, useSystemDefault);
    emojiGridFragment.setArguments(args);
    emojiGridFragment.setRecents(recents);
    return emojiGridFragment;
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    return inflater.inflate(R.layout.emoticons_grid, container, false);
}

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    GridView gridView = (GridView) view.findViewById(R.id.emoticons_grid);
    Bundle bundle = getArguments();
    if (bundle == null) {
        mData = People.DATA;
        mUseSystemDefault = false;
    } else {
        Object[] o = (Object[]) getArguments().getSerializable("emojicons");
        mData = Arrays.asList(o).toArray(new Emojicon[o.length]);
        mUseSystemDefault = bundle.getBoolean(USE_SYSTEM_DEFAULT_KEY);
    }
    gridView.setAdapter(new EmojiAdapter(view.getContext(), mData, mUseSystemDefault));
    gridView.setOnItemClickListener(this);
}

@Override
public void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    outState.putSerializable("emojicons", mData);
}

@Override
public void onAttach(Activity activity) {
    super.onAttach(activity);
    if (activity instanceof OnEmojiconClickedListener) {
        mOnEmojiconClickedListener = (OnEmojiconClickedListener) activity;
    } else if (getParentFragment() instanceof OnEmojiconClickedListener) {
        mOnEmojiconClickedListener = (OnEmojiconClickedListener) getParentFragment();
    } else {
        throw new IllegalArgumentException(activity + " must implement interface " + OnEmojiconClickedListener.class.getSimpleName());
    }
}

@Override
public void onDetach() {
    mOnEmojiconClickedListener = null;
    super.onDetach();
}

@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    if (mOnEmojiconClickedListener != null) {
        mOnEmojiconClickedListener.onEmojiconClicked((Emojicon) parent.getItemAtPosition(position));
    }
    if (mRecents != null) {
        mRecents.addRecentEmoji(view.getContext(), ((Emojicon) parent
            .getItemAtPosition(position)));
    }
}

private void setRecents(EmojiconRecents recents) {
    mRecents = recents;
}

public interface OnEmojiconClickedListener {
    void onEmojiconClicked(Emojicon emojicon);
}
}

感谢您的帮助

1 个答案:

答案 0 :(得分:1)

我通过将此库添加为依赖项而不是内部代码来解决此错误。

compile 'com.rockerhieu.emojicon:library:1.3.3'

在build.gradle文件中添加了这个

并更改了对其他文件中包的引用。