当我点击分享图标然后应用程序停止并且它没有在logcat中显示任何错误,只有五行对我来说似乎不是一个错误。此外,还有5个片段,当我在打开应用程序后打开片段4时,它停止但是当我转到片段2然后3然后5时,它不会停止。甚至我的minSdkVersion 15和targetSdkVersion 18,我的应用程序没有运行,它在大多数设备中都停止了。
appcompat上的gradle(模块:应用程序)中显示警告
all com.android.support libraries must use the exact same version found versions 26.1.0, 25.2.0
这是我的傻瓜
apply plugin: 'com.android.application'
apply plugin: 'realm-android'
android {
compileSdkVersion 26
buildToolsVersion "26.0.2"
defaultConfig {
applicationId "com.balrajarpit.balrajarpit"
minSdkVersion 15
targetSdkVersion 18
versionCode 2
versionName "1.1"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
multiDexEnabled = true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
dexOptions {
javaMaxHeapSize "4g"
}
}
}
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:26.+'
compile 'com.android.support:design:26.+'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.android.support:recyclerview-v7:26.+'
compile 'com.github.bumptech.glide:glide:3.7.0'
compile 'com.android.support:cardview-v7:26.+'
compile 'com.android.support:support-vector-drawable:26.+'
compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.5'
compile 'com.android.support:support-v4:26.+'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.mcxiaoke.volley:library:1.0.19'
compile 'com.google.code.gson:gson:2.2.4'
compile 'com.google.android.gms:play-services:11.+'
compile('com.squareup.retrofit2:retrofit:2.0.0-beta4') {
exclude module: 'okhttp'
}
compile 'com.squareup.okhttp3:okhttp:3.2.0'
compile 'com.squareup.okhttp3:logging-interceptor:3.0.1'
compile 'com.squareup.retrofit2:converter-gson:2.1.0'
compile 'com.squareup.picasso:picasso:2.5.2'
// ripple effect library
compile 'com.balysv:material-ripple:1.0.2'
testCompile 'junit:junit:4.12'
}
apply plugin: 'com.google.gms.google-services'
活动
import android.app.Dialog;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.Handler;
import android.support.design.widget.Snackbar;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.ActivityOptionsCompat;
import android.support.v4.view.ViewCompat;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.text.Html;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.balysv.materialripple.MaterialRippleLayout;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
import com.balrajarpit.balrajarpit.adapter.AdapterComments;
import com.balrajarpit.balrajarpit.connection.API;
import com.balrajarpit.balrajarpit.connection.RestAdapter;
import com.balrajarpit.balrajarpit.connection.callbacks.CallbackDetailsPost;
import com.balrajarpit.balrajarpit.data.AppConfig;
import com.balrajarpit.balrajarpit.data.Constant;
import com.balrajarpit.balrajarpit.data.SharedPref;
import com.balrajarpit.balrajarpit.model.Comment;
import com.balrajarpit.balrajarpit.model.Post;
import com.balrajarpit.balrajarpit.realm.RealmController;
import com.balrajarpit.balrajarpit.utils.NetworkCheck;
import com.balrajarpit.balrajarpit.utils.Tools;
import java.util.List;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
public class ActivityPostDetails extends AppCompatActivity {
public static final String EXTRA_OBJC = "key.EXTRA_OBJC";
public static final String EXTRA_NOTIF = "key.EXTRA_NOTIF";
// give preparation animation activity transition
public static void navigate(AppCompatActivity activity, View transitionView, Post obj) {
Intent intent = new Intent(activity, ActivityPostDetails.class);
intent.putExtra(EXTRA_OBJC, obj);
ActivityOptionsCompat options = ActivityOptionsCompat.makeSceneTransitionAnimation(activity, transitionView, EXTRA_OBJC);
ActivityCompat.startActivity(activity, intent, options.toBundle());
}
private Toolbar toolbar;
private ActionBar actionBar;
private View parent_view;
private MenuItem read_later_menu;
private SwipeRefreshLayout swipe_refresh;
// extra obj
private Post post;
private boolean from_notif;
private SharedPref sharedPref;
private boolean flag_read_later;
private Call<CallbackDetailsPost> callbackCall = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_post_details);
parent_view = findViewById(android.R.id.content);
swipe_refresh = (SwipeRefreshLayout) findViewById(R.id.swipe_refresh_layout);
sharedPref = new SharedPref(this);
// animation transition
ViewCompat.setTransitionName(findViewById(R.id.image), EXTRA_OBJC);
// get extra object
post = (Post) getIntent().getSerializableExtra(EXTRA_OBJC);
from_notif = getIntent().getBooleanExtra(EXTRA_NOTIF, false);
initToolbar();
displayPostData(true);
prepareAds();
if (post.isDraft()) requestAction();
// on swipe
swipe_refresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
requestAction();
}
});
// get enabled controllers
Tools.requestInfoApi(this);
// analytics tracking
ThisApplication.getInstance().trackScreenView("View post : "+post.title_plain);
}
private void initToolbar() {
toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
actionBar = getSupportActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setHomeButtonEnabled(true);
actionBar.setTitle("");
}
private void requestDetailsPostApi() {
API api = RestAdapter.createAPI();
callbackCall = api.getPostDetialsById(post.id);
callbackCall.enqueue(new Callback<CallbackDetailsPost>() {
@Override
public void onResponse(Call<CallbackDetailsPost> call, Response<CallbackDetailsPost> response) {
CallbackDetailsPost resp = response.body();
if (resp != null && resp.status.equals("ok")) {
post = resp.post;
displayPostData(false);
swipeProgress(false);
} else {
onFailRequest();
}
}
@Override
public void onFailure(Call<CallbackDetailsPost> call, Throwable t) {
if (!call.isCanceled()) onFailRequest();
}
});
}
private void requestAction() {
showFailedView(false, "");
swipeProgress(true);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
requestDetailsPostApi();
}
}, Constant.DELAY_TIME_MEDIUM);
}
private void onFailRequest() {
swipeProgress(false);
if (NetworkCheck.isConnect(this)) {
showFailedView(true, getString(R.string.failed_text));
} else {
showFailedView(true, getString(R.string.no_internet_text));
}
}
private void displayPostData(boolean is_draft) {
((TextView) findViewById(R.id.title)).setText(Html.fromHtml(post.title));
WebView webview = (WebView) findViewById(R.id.content);
String html_data = "<style>img{max-width:100%;height:auto;} iframe{width:100%;}</style> ";
html_data += post.content;
webview.getSettings().setJavaScriptEnabled(true);
webview.getSettings();
webview.getSettings().setBuiltInZoomControls(true);
webview.setBackgroundColor(Color.TRANSPARENT);
webview.setWebChromeClient(new WebChromeClient());
webview.loadData(html_data, "text/html; charset=UTF-8", null);
// disable scroll on touch
webview.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
return (event.getAction() == MotionEvent.ACTION_MOVE);
}
});
((TextView) findViewById(R.id.date)).setText(Tools.getFormatedDate(post.date));
((TextView) findViewById(R.id.comment)).setText(post.comment_count + "");
((TextView) findViewById(R.id.tv_comment)).setText(getString(R.string.show_tv_comments) + " (" + post.comment_count + ")");
((TextView) findViewById(R.id.category)).setText(Html.fromHtml(Tools.getCategoryTxt(post.categories)));
Tools.displayImageThumbnail(this, post, ((ImageView) findViewById(R.id.image)));
if(is_draft){
return;
}
// when show comments click
((MaterialRippleLayout) findViewById(R.id.bt_show_comment)).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (post.comments.size() <= 0) {
Snackbar.make(parent_view, R.string.post_have_no_comment, Snackbar.LENGTH_SHORT).show();
return;
}
dialogShowComments(post.comments);
}
});
// when post comments click
((MaterialRippleLayout) findViewById(R.id.bt_send_comment)).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (!AppConfig.MUST_REGISTER_TO_COMMENT) {
Intent i = new Intent(ActivityPostDetails.this, ActivityWebView.class);
if (sharedPref.isRespondEnabled()) {
i = new Intent(ActivityPostDetails.this, ActivitySendComment.class);
}
i.putExtra(EXTRA_OBJC, post);
startActivity(i);
} else {
Tools.dialogCommentNeedLogin(ActivityPostDetails.this, post.url);
}
}
});
Snackbar.make(parent_view, R.string.post_detail_displayed_msg, Snackbar.LENGTH_SHORT).show();
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int item_id = item.getItemId();
if (item_id == android.R.id.home) {
onBackPressed();
} else if (item_id == R.id.action_share) {
Tools.methodShare(ActivityPostDetails.this, post);
} else if (item_id == R.id.action_later) {
if (post.isDraft()) {
Snackbar.make(parent_view, R.string.cannot_add_to_read_later, Snackbar.LENGTH_SHORT).show();
return true;
}
String str;
if (flag_read_later) {
RealmController.with(this).deletePost(post.id);
str = getString(R.string.remove_from_msg);
} else {
RealmController.with(this).savePost(post);
str = getString(R.string.added_to_msg);
}
Snackbar.make(parent_view, "Post " + str + " Read Later", Snackbar.LENGTH_SHORT).show();
refreshReadLaterMenu();
} else if (item_id == R.id.action_browser) {
Tools.directLinkToBrowser(this, post.url);
}
return super.onOptionsItemSelected(item);
}
@Override
public boolean onCreateOptionsMenu(final Menu menu) {
getMenuInflater().inflate(R.menu.menu_activity_post_details, menu);
read_later_menu = menu.findItem(R.id.action_later);
refreshReadLaterMenu();
return true;
}
private void dialogShowComments(List<Comment> items) {
final Dialog dialog = new Dialog(ActivityPostDetails.this);
dialog.setCancelable(true);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); // before
dialog.setContentView(R.layout.dialog_comments);
WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
lp.copyFrom(dialog.getWindow().getAttributes());
lp.width = WindowManager.LayoutParams.MATCH_PARENT;
lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
RecyclerView recyclerView = (RecyclerView) dialog.findViewById(R.id.recyclerView);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerView.setHasFixedSize(true);
AdapterComments mAdapter = new AdapterComments(this, items);
recyclerView.setAdapter(mAdapter);
((ImageView) dialog.findViewById(R.id.img_close)).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
dialog.dismiss();
}
});
dialog.show();
dialog.getWindow().setAttributes(lp);
}
private void refreshReadLaterMenu() {
flag_read_later = RealmController.with(this).getPost(post.id) != null;
Drawable drawable = read_later_menu.getIcon();
if (flag_read_later) {
drawable.setColorFilter(Color.BLACK, PorterDuff.Mode.SRC_ATOP);
} else {
drawable.setColorFilter(Color.WHITE, PorterDuff.Mode.SRC_ATOP);
}
}
private void prepareAds() {
if (AppConfig.ENABLE_ADSENSE && NetworkCheck.isConnect(getApplicationContext())) {
AdView mAdView = (AdView) findViewById(R.id.ad_view);
AdRequest adRequest = new AdRequest.Builder().addTestDevice(AdRequest.DEVICE_ID_EMULATOR).build();
// Start loading the ad in the background.
mAdView.loadAd(adRequest);
} else {
((RelativeLayout) findViewById(R.id.banner_layout)).setVisibility(View.GONE);
}
}
private void showFailedView(boolean show, String message) {
View lyt_failed = (View) findViewById(R.id.lyt_failed);
View lyt_main_content = (View) findViewById(R.id.lyt_main_content);
((TextView) findViewById(R.id.failed_message)).setText(message);
if (show) {
lyt_main_content.setVisibility(View.GONE);
lyt_failed.setVisibility(View.VISIBLE);
} else {
lyt_main_content.setVisibility(View.VISIBLE);
lyt_failed.setVisibility(View.GONE);
}
((Button) findViewById(R.id.failed_retry)).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
requestAction();
}
});
}
private void swipeProgress(final boolean show) {
if (!show) {
swipe_refresh.setRefreshing(show);
return;
}
swipe_refresh.post(new Runnable() {
@Override
public void run() {
swipe_refresh.setRefreshing(show);
}
});
}
@Override
public void onBackPressed() {
if(from_notif) {
startActivity(new Intent(getApplicationContext(), ActivityMain.class));
finish();
} else {
super.onBackPressed();
}
}
}
logcat的
12-09 13:56:43.962 6867-6914/com.balrajarpit.balrajarpit D/FA: Logging event (FE): app_exception(_ae), Bundle[{firebase_event_origin(_o)=crash, firebase_screen_class(_sc)=ActivityPostDetails, firebase_screen_id(_si)=8020478545849927104, timestamp=1512808003957, fatal=1}]
12-09 13:56:43.979 6867-6914/com.balrajarpit.balrajarpit V/FA: Connecting to remote service
12-09 13:56:43.985 6867-6914/com.balrajarpit.balrajarpit V/FA: Recording user engagement, ms: 23008
12-09 13:56:43.991 6867-6914/com.balrajarpit.balrajarpit D/FA: Logging event (FE): user_engagement(_e), Bundle[{firebase_event_origin(_o)=auto, engagement_time_msec(_et)=23008, firebase_screen_class(_sc)=ActivityPostDetails, firebase_screen_id(_si)=8020478545849927104}]
12-09 13:56:44.012 6867-6914/com.balrajarpit.balrajarpit V/FA: Connection attempt already in progress
答案 0 :(得分:0)
我不确定在这种情况下是否存在问题,但使用不同版本的支持库会导致运行时崩溃。您可以通过在(android studio)终端中执行以下命令找到使用不同版本(可能由其他库内部使用)的那些:
gradlew -q dependencies app:dependencies --configuration compile
如果命令不起作用,您可能必须先配置gradle包装器。为此,请将以下内容添加到项目build.gradle文件中:
task wrapper(type: Wrapper) {
gradleVersion = '4.1'
}
并执行命令
gradle wrapper
终端如果它仍然不起作用,gradle可能不在您的PATH中,如果您想要添加它,可以在Android Studio安装文件夹中找到它。
一旦您知道哪个版本使用不同的版本,只需将其作为依赖项自行添加到正确的版本中,以覆盖其他版本并同步。
当我遇到问题时,这对我有用,希望它有所帮助!