应用程序在调试构建类型中工作正常,但后来我生成了已签名的APK并尝试运行应用程序,但在签名APK时出错。
我在这里分享一些其他资源以获得更多说明。
BuildType:
release {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
Proguardrules:
-dontwarn com.roughike.bottombar.**
-dontwarn okio.**
-dontwarn retrofit2.**
-dontwarn javax.annotation.**
-dontwarn javax.annotation.Nullable
-dontwarn javax.annotation.ParametersAreNonnullByDefault
-dontwarn com.squareup.okhttp.**
-keep class android.support.v7.widget.SearchView { *; }
# Platform calls Class.forName on types which do not exist on Android to determine platform.
-dontnote retrofit2.Platform
# Platform used when running on Java 8 VMs. Will not be used at runtime.
-dontwarn retrofit2.Platform$Java8
堆栈跟踪:
09-27 10:30:23.701 23486-23486/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.fastfashion.videostatusmedia, PID: 23486
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.fastfashion.videostatusmedia/com.fastfashion.videostatusmedia.activity.MainActivity}: android.view.InflateException: Binary XML file line #0: Binary XML file line #1: Error inflating class x
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2449)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2509)
at android.app.ActivityThread.access$1000(ActivityThread.java:153)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1373)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:5527)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:739)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:629)
Caused by: android.view.InflateException: Binary XML file line #0: Binary XML file line #1: Error inflating class x
at android.view.LayoutInflater.inflate(LayoutInflater.java:543)
at android.view.LayoutInflater.inflate(LayoutInflater.java:427)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at android.support.v7.app.k.x(SourceFile:430)
at android.support.v7.app.k.w(SourceFile:323)
at android.support.v7.app.k.b(SourceFile:284)
at android.support.v7.app.c.setContentView(SourceFile:139)
at com.fastfashion.videostatusmedia.activity.MainActivity.onCreate(SourceFile:46)
at android.app.Activity.performCreate(Activity.java:6303)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1108)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2402)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2509)
at android.app.ActivityThread.access$1000(ActivityThread.java:153)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1373)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:5527)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:739)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:629)
Caused by: android.view.InflateException: Binary XML file line #1: Error inflating class x
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:780)
at android.view.LayoutInflater.parseInclude(LayoutInflater.java:945)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:835)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:802)
at android.view.LayoutInflater.inflate(LayoutInflater.java:519)
at android.view.LayoutInflater.inflate(LayoutInflater.java:427)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at android.support.v7.app.k.x(SourceFile:430)
at android.support.v7.app.k.w(SourceFile:323)
at android.support.v7.app.k.b(SourceFile:284)
at android.support.v7.app.c.setContentView(SourceFile:139)
at com.fastfashion.videostatusmedia.activity.MainActivity.onCreate(SourceFile:46)
at android.app.Activity.performCreate(Activity.java:6303)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1108)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2402)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2509)
at android.app.ActivityThread.access$1000(ActivityThread.java:153)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1373)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:5527)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:739)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:629)
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.view.x" on path: DexPathList[[zip file "/data/app/com.fastfashion.videostatusmedia-1/base.apk"],nativeLibraryDirectories=[/data/app/com.fastfashion.videostatusmedia-1/lib/arm64, /vendor/lib64, /system/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
at android.view.LayoutInflater.createView(LayoutInflater.java:587)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:681)
at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:68)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:698)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:766)
at android.view.LayoutInflater.parseInclude(LayoutInflater.java:945)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:835)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:802)
at android.view.LayoutInflater.inflate(LayoutInflater.java:519)
at android.view.LayoutInflater.inflate(LayoutInflater.java:427)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at android.support.v7.app.k.x(SourceFile:430)
at android.support.v7.app.k.w(SourceFile:323)
at android.support.v7.app.k.b(SourceFile:284)
at android.support.v7.app.c.setContentView(SourceFile:139)
at com.fastfashion.videostatusmedia.activity.MainActivity.onCreate(SourceFile:46)
at android.app.Activity.performCreate(Activity.java:6303)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1108)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2402)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2509)
at android.app.ActivityThread.access$1000(ActivityThread.java:153)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1373)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:5527)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:739)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:629)
Suppressed: java.lang.ClassNotFoundException: android.view.x
at java.lang.Class.classForName(Native Method)
at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
... 29 more
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available
的AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.fastfashion.videostatusmedia">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.GET_TASKS" />
<application
android:name=".app.MyApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher_logo"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_logo_round"
android:supportsRtl="true"
android:theme="@style/AppTheme"
android:fullBackupContent="@xml/backup_descriptor"
tools:ignore="GoogleAppIndexingWarning">
<activity
android:name=".activity.MainActivity"
android:screenOrientation="portrait"
android:theme="@style/AppTheme.NoActionBar"
android:windowSoftInputMode="adjustPan|adjustNothing">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".activity.VideoActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:screenOrientation="portrait"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name=".activity.SearchActivity"
android:screenOrientation="portrait"
android:theme="@style/AppTheme.NoActionBar" />
<activity android:name=".activity.SplashActivity" android:theme="@style/Theme.AppCompat.Light.NoActionBar.FullScreen" android:configChanges="orientation|keyboardHidden|screenSize"
android:screenOrientation="portrait">
</activity>
<receiver
android:name=".receiver.DownloadReceiver"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.DOWNLOAD_COMPLETE" />
</intent-filter>
</receiver>
<service android:name=".service.MyFirebaseInstanceIDService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
</intent-filter>
</service>
<service android:name=".service.MyFirebaseMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>
</application>
</manifest>
activity_main.xml中
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.fastfashion.videostatusmedia.activity.MainActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarTheme">
<FrameLayout
android:id="@+id/toolbar_container"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar
android:id="@+id/main_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/colorPrimary"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Dark"
app:layout_scrollFlags="scroll|enterAlways"/>
<com.miguelcatalan.materialsearchview.MaterialSearchView
android:id="@+id/search_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</FrameLayout>
</android.support.design.widget.AppBarLayout>
<FrameLayout
android:id="@+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
<com.roughike.bottombar.BottomBar
android:id="@+id/main_bottom_bar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layout_gravity="bottom"
app:bb_inActiveTabAlpha="1.0"
app:bb_inActiveTabColor="#7e7e7e"
app:bb_titleTextAppearance="@style/BottomBarTextAppearance"
app:bb_tabXmlResource="@xml/bottombar_main_tabs"
app:bb_titleTypeFace="fonts/prestij-regular.otf"
app:bb_behavior="shy"
android:background="#f7f5f5"
app:bb_showShadow="false"/>
<FrameLayout
android:id="@+id/transparentSearchOverlay"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/black_trans"
android:visibility="gone" />
</android.support.design.widget.CoordinatorLayout>
MainActivity.java
public class MainActivity extends BaseActivity {
private Handler mHandler;
private Toolbar mainToolbar;
private BottomBar mBottomBar;
private MaterialSearchView searchView;
private boolean isDoubleBackPressed = false;
private Handler handler = new Handler();
Runnable runnable = new Runnable() {
@Override
public void run() {
showShortToast("Press again BACK to exit.");
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if(PrefManager.getInstance().isFirstTimeLaunch()) {
startActivity(new Intent(this, SplashActivity.class));
finish();
return;
}
MobileAds.initialize(this, getString(R.string.ad_app_id));
mHandler = new Handler();
mainToolbar = findViewById(R.id.main_toolbar);
setSupportActionBar(mainToolbar);
mBottomBar = findViewById(R.id.main_bottom_bar);
mBottomBar.setTabSelectionInterceptor(new TabSelectionInterceptor() {
@Override
public boolean shouldInterceptTabSelection(int oldTabId, int newTabId) {
if(newTabId == R.id.tab_upload) {
showLongToast("Coming Soon....");
return true;
}
return false;
}
});
mBottomBar.setOnTabSelectListener(new OnTabSelectListener() {
@Override
public void onTabSelected(int tabId) {
switch (tabId) {
case R.id.tab_home:
loadFragment(R.string.title_home, HomeFragment.newInstance("default"));
break;
case R.id.tab_trending:
loadFragment(R.string.title_trending, HomeFragment.newInstance("trending"));
break;
case R.id.tab_downloads:
loadFragment(R.string.title_downloads, DownloadFragment.newInstance());
break;
default:
break;
}
}
});
initSearchBar();
}
private void initSearchBar() {
searchView = findViewById(R.id.search_view);
final View transparentSearchScreen = findViewById(R.id.transparentSearchOverlay);
searchView.setBackIcon(ContextCompat.getDrawable(getApplicationContext(), R.drawable.ic_action_navigation_arrow_back));
searchView.setCloseIcon(ContextCompat.getDrawable(getApplicationContext(), R.drawable.ic_action_navigation_close));
this.searchView.setHintTextColor(ContextCompat.getColor(getApplicationContext(), android.R.color.darker_gray));
searchView.dismissSuggestions();
searchView.setBackgroundColor(ContextCompat.getColor(getApplicationContext(), android.R.color.white));
searchView.setOnSearchViewListener(new MaterialSearchView.SearchViewListener() {
@Override
public void onSearchViewShown() {
transparentSearchScreen.setVisibility(View.VISIBLE);
}
@Override
public void onSearchViewClosed() {
transparentSearchScreen.setVisibility(View.GONE);
}
});
transparentSearchScreen.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(searchView.isOpaque()) {
searchView.closeSearch();
}
}
});
searchView.setOnQueryTextListener(new MaterialSearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
if(query.equals("")) {
showShortToast("Enter something for search");
} else {
Intent intent = new Intent(MainActivity.this, SearchActivity.class);
intent.putExtra(SearchActivity.EXTRA_SEARCH_STRING, query);
startActivity(intent);
searchView.setQuery("", false);
}
return false;
}
@Override
public boolean onQueryTextChange(String newText) {
return false;
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main_menu, menu);
this.searchView.setMenuItem(menu.findItem(R.id.action_search));
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_share:
shareApp();
break;
case R.id.action_rate:
rateApp();
break;
case R.id.action_feedback:
feedbackApp();
break;
}
return super.onOptionsItemSelected(item);
}
private void loadFragment(int id, final Fragment fragment) {
final String title = getString(id);
Runnable mPendingRunnable = new Runnable() {
@Override
public void run() {
setToolbarTitle(title);
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
fragmentTransaction.setCustomAnimations(android.R.anim.fade_in, android.R.anim.fade_out);
fragmentTransaction.add(R.id.fragment_container, fragment, title);
fragmentTransaction.commitAllowingStateLoss();
}
};
if (mPendingRunnable != null) {
mHandler.post(mPendingRunnable);
}
}
private void setToolbarTitle(String title) {
if (getSupportActionBar() != null)
getSupportActionBar().setTitle(title);
}
@Override
public void onBackPressed() {
if(this.searchView.isSearchOpen()) {
this.searchView.closeSearch();
return;
}
if(isDoubleBackPressed) {
handler.removeCallbacks(runnable);
super.onBackPressed();
}
if(R.id.tab_home != mBottomBar.getCurrentTabId()) {
mBottomBar.selectTabWithId(R.id.tab_home);
return;
}
isDoubleBackPressed = true;
this.handler.postDelayed(runnable,300);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
isDoubleBackPressed = false;
}
}, 2000);
}
private void shareApp() {
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra(Intent.EXTRA_SUBJECT, Utility.shareSubject);
shareIntent.putExtra(Intent.EXTRA_TEXT, "\nGet all categories status in one app. Share status and become popular in social market. \n\n 'Video Status'\n\n" + "https://play.google.com/store/apps/details?id=" + getPackageName() + "\n\n");
startActivity(Intent.createChooser(shareIntent, "Share with"));
}
private void rateApp() {
Uri uri = Uri.parse("market://details?id=" + getPackageName());
Intent myAppLinkToMarket = new Intent(Intent.ACTION_VIEW, uri);
if(Build.VERSION.SDK_INT >= 21) {
myAppLinkToMarket.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT);
}
myAppLinkToMarket.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY |
Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
try {
startActivity(myAppLinkToMarket);
} catch (ActivityNotFoundException e) {
startActivity(new Intent(Intent.ACTION_VIEW,
Uri.parse("https://play.google.com/store/apps/details?id=" + getPackageName())));
}
}
private void feedbackApp() {
Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mailto", "fastfashion111@gmail.com", null));
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Status Video - Feedback");
emailIntent.putExtra(Intent.EXTRA_TEXT, "Write your feedback content here.");
try {
startActivity(Intent.createChooser(emailIntent, "Send Feedback"));
} catch (android.content.ActivityNotFoundException ex) {
showShortToast("There is no email client installed.");
}
}
}
BaseActivity.java
public class BaseActivity extends AppCompatActivity {
protected Toast toast;
protected void showShortToast(String msg) {
if(toast == null)
toast = Toast.makeText(this, msg, Toast.LENGTH_SHORT);
else
toast.setText(msg);
toast.show();
}
protected void showLongToast(String msg) {
if(toast == null)
toast = Toast.makeText(this, msg, Toast.LENGTH_LONG);
else
toast.setText(msg);
toast.show();
}
}
如果需要其他代码请告诉我,我可以在此分享。我已经尝试在stackoverflow上找到解决方案,但我根本找不到任何东西。