Exception java.lang.NoSuchMethodError after using getBlockSizeLong method
I created a chat project using android studio 1.0.1
this is the gradle build properties to
apply the plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "chat.mchattrav.chattrav"
minSdkVersion 5
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
}
when i run the app i get this error message immediately
unfortunately the application has stopped
when i debug the application i get this exception info
java.lang.NoSuchMethodError: android.os.StatFs.getBlockSizeLong
I seem to be using a lower api level than "18" which is required by this method
can I solve this without having to increase the api level "minSdkVersion"?
can i use the support library?
source to share
If you need to support SDKs below 18 then you need to handle that.
There are 2 methods:
public int getBlockSize () Added in API1, deprecated in API18
and
public long getBlockSizeLong () Added in API18
Your project is using the second one, you need to find all the ways to use and take care of the android version like
StatFs staFs = new StatFs("path");
long size = 0;
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2){
size = staFs.getBlockSizeLong();
}else {
size = staFs.getBlockSize();
}
// use size ...
source to share