2017-04-03 109 views
3

我是Android編程和StackOverflow的新手。這是我的第一個問題,但是我之前使用過StackOverflow平臺來解決這個問題。現在,我的問題。我有一個Android應用程序,可以在SDK 11中的所有Android設備上正常運行。但是,在SDK 25的更新中,它會在預棒棒糖設備上崩潰。前棒棒糖設備上的Android紋波可繪製錯誤 - Android SDK 25

我的日誌貓如下:

Could not find class 'android.graphics.drawable.RippleDrawable', referenced from method android.support.v7.widget.AppCompatImageHelper.hasOverlappingRendering 

我已經包含在我的gradle這個vectorDrawables.useSupportLibrary = true。我的minSdkVersion = 11targetSdkVersion = 25,supportLibraryVersion = 25.2.0

我試過了所有的建議,我可以在這裏找到,但沒有作品。所以請大家,我需要你的幫助。我渴望學習,以便我可以解決這個問題。

謝謝。

+0

您使用哪種gradle版本? –

+0

我使用的是Gradle版本3.3和插件版本2.3 –

+0

這是正確的。你可以通過刪除所有其他代碼來分享項目嗎?除非試圖引用導致此異常的圖像 –

回答

2

有時調試可能是一種痛苦,上面的問題是我原始代碼中一個簡單錯誤的結果。人類會犯錯......

現在來解決。我最初的代碼如下,如果你看看敏銳,你會注意到,如果該設備是低於23

 if(Build.VERSION.SDK_INT >= 23) { 
     if(checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) { 
      // Storage permissions is already available, save profile photo 

      initialization(); 
     } else { 
      // Providing additional rational to the user if permission was not granted 
      if(shouldShowRequestPermissionRationale(Manifest.permission.WRITE_EXTERNAL_STORAGE)) { 
       Toast.makeText(this, "Storage permission is needed to save your profile photo.", Toast.LENGTH_LONG).show(); 
      } 

      requestPermissions(new String[] {Manifest.permission.READ_CONTACTS}, WRITE_EXTERNAL_STORAGE); 
     } 
    } 

版這是初始化方法檢查Build.Version if語句之間的初始化代碼不運行。在Android版本低於23的設備中,它沒有運行,從而觸發Could not find class錯誤。不過,我仍然沒有弄清楚這是如何與Ripple Drawable相關的,因爲我的代碼中沒有使用Vector Drawables。因此,任何人誰可以閱讀這可能會提供一些線索到原因

private void initialization() { 

    hoverView = (View) findViewById(R.id.hoverView); 
    hoverView.setVisibility(View.GONE); 

    mExitAppDialog = new HookUpDialog(this); 
    mExitAppDialog.setMessage(getString(R.string.exit_app_message)); 
    mExitAppDialog.setOnButtonClickListener(HookUpDialog.BUTTON_OK, 
      new OnClickListener() { 

       @Override 
       public void onClick(View v) { 
        mExitAppDialog.dismiss(); 

        if (WallActivity.getInstance() != null) { 
         WallActivity.getInstance().finish(); 
        } 
        sInstance.finish(); 

        /* Informing the user, to press back again to exit */ 
        Toast.makeText(getApplicationContext(), 
          R.string.press_back_again_to_exit, 
          Toast.LENGTH_SHORT).show(); 

       } 
      }); 
    mExitAppDialog.setOnButtonClickListener(HookUpDialog.BUTTON_CANCEL, 
      new OnClickListener() { 

       @Override 
       public void onClick(View v) { 
        mExitAppDialog.dismiss(); 

       } 
      }); 
    mLlRecentActivity = (LinearLayout) findViewById(R.id.llRecentActivity); 
    mNoActivitiesView = (TextView) findViewById(R.id.tvNoRecentActivities); 
} 

現在到了完整的代碼,包括與Android版本23及以下的否則,如果修復了設備。

  if(Build.VERSION.SDK_INT >= 23) { 
     if(checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) { 
      // Storage permissions is already available, save profile photo 

      initialization(); 
     } else { 
      // Providing additional rational to the user if permission was not granted 
      if(shouldShowRequestPermissionRationale(Manifest.permission.WRITE_EXTERNAL_STORAGE)) { 
       Toast.makeText(this, "Storage permission is needed to save your profile photo.", Toast.LENGTH_LONG).show(); 
      } 

      requestPermissions(new String[] {Manifest.permission.READ_CONTACTS}, WRITE_EXTERNAL_STORAGE); 
     } 
    } else if (Build.VERSION.SDK_INT < 23) { 
     // Storage permissions is already available, save profile photo 

     initialization(); 

    } 

感謝@Anurag Singh,經過數小時的測試和重新測試,我能夠看到這一點。谷歌搜索和谷歌搜索。

相關問題