可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
after solving a jdk zero value error , now im facing this one, i did a little research but it seems i cant get to the point, here is the log error
im really confused what it can be, i readed and cant get to the error
my app:gradle is this
apply plugin: 'com.android.application' android { compileSdkVersion 23 buildToolsVersion "24.0.2" defaultConfig { applicationId "me.me2.com.myapp" minSdkVersion 15 targetSdkVersion 23 versionCode 1 versionName "1.0" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } } dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) testCompile 'junit:junit:4.12' compile 'com.android.support:appcompat-v7:23.4.0' compile 'com.android.support:design:23.4.0' compile 'com.android.support:recyclerview-v7:23.4.0' compile 'com.android.support:cardview-v7:23.4.0' compile 'com.google.firebase:firebase-storage:9.4.0' compile 'com.google.firebase:firebase-database:9.4.0' compile 'com.google.firebase:firebase-auth:9.4.0' compile 'com.firebaseui:firebase-ui-database:0.4.4' compile 'com.squareup.picasso:picasso:2.5.2' } apply plugin: 'com.google.gms.google-services'
here is my style folder
and my mainactivity.class if needed
public class MainActivity extends AppCompatActivity { VideoView videoView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // VideoView videoView = (VideoView) findViewById(R.id.videoview); videoView.setVideoURI(Uri.parse("android.resource://"+getPackageName() + "/" +R.raw.video)); videoView.requestFocus(); /** * Loop */ videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() { @Override public void onPrepared(MediaPlayer mp) { videoView.start(); mp.setLooping(true); } }); } public void Login(View view) { Intent intent = new Intent(this, FragmentMain.class); startActivity(intent); // finish(); } public void Registro(View view) { Intent intent = new Intent(this, Registro.class); startActivity(intent); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.menu_main, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); //noinspection SimplifiableIfStatement if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } }
thanks
回答1:
IF you're using Gradle Plugin 2.0, you need to make changes in your gradle
:
// Gradle Plugin 2.0+ android { defaultConfig { vectorDrawables.useSupportLibrary = true } }
If you are using Gradle 1.5 you’ll use instead of previus:
// Gradle Plugin 1.5 android { defaultConfig { // Stops the Gradle plugin's automatic rasterization of vectors generatedDensities = [] } // Flag to tell aapt to keep the attribute ids around // This is handled for you by the 2.0+ Gradle Plugin aaptOptions { additionalParameters "--no-version-vectors" } }
Check also: Update Android Support Library to 23.2.0 cause error: XmlPullParserException Binary XML file line #17 tag requires viewportWidth > 0.
Android Support Library Ref.: Support Vector Drawables and Animated Vector Drawables.
Also update Android Support dependencies from
compile 'com.android.support:appcompat-v7:23.4.0' compile 'com.android.support:design:23.4.0' compile 'com.android.support:recyclerview-v7:23.4.0' compile 'com.android.support:cardview-v7:23.4.0'
to
compile 'com.android.support:appcompat-v7:24.2.0' compile 'com.android.support:design:24.2.0' compile 'com.android.support:recyclerview-v7:24.2.0' compile 'com.android.support:cardview-v7:24.2.0'
as you're already using build-tools in version of 24.0.2
.
回答2:
If above any solution is not worked , you can add below line in Activity
static { AppCompatDelegate.setCompatVectorFromResourcesEnabled(true); }
and of course update your gradle and appcompat to latest version. this process was worked in my case
回答3:
I ran into this issue in Xamarin.Android with Xamarin.Android.Support.Design 24.0.2. Here is how I solved it:
Added the following line to my Application class OnCreate
:
AppCompatDelegate.CompatVectorFromResourcesEnabled = true;
Replaced:
var upArrow = ContextCompat.GetDrawable(this, Resource.Drawable.abc_ic_ab_back_material);
With:
var upArrow = ResourcesCompat.GetDrawable(Resources, Resource.Drawable.abc_ic_ab_back_material, null);
回答4:
None of these worked for me. But this did:
Change
android:src="@drawable/your_drawable"
to
app:srcCompat="@drawable/your_drawable"
回答5:
I have tried all solutions mentioned above. Nothing worked for me. The only thing worked for me is very simple is to update all support libraries to latest version as this bug has been fixed in it. So i simple did the below thing in gradle file; updated SDK and support to 25.
android { compileSdkVersion 25 buildToolsVersion "25" defaultConfig { targetSdkVersion 25 } } In dependencies compile 'com.android.support:appcompat-v7:25.1.0' compile 'com.android.support:design:25.1.0' compile 'com.android.support:recyclerview-v7:25.1.0'
回答6:
Since this page is the first result of google android.content.res.Resources$NotFoundException: File res/drawable/
, I want to share that this exception might caused by your foo.xml contains improper code.
e.g. foo.xml
:
This xml contains
which compiled successfully but throws exception at Runtime, vary in different app.
回答7:
Ok, i just solved my problem, the problem was my gradle outdated and my sdk , so if anyone is running with this problem just do this steps
1.- Make sure your libs are updated as piotrek1543 says above 2.- Update your sdk if is necesary 3.- Update your gradle files (VERY IMPORTANT) just go to the project gradle and add this
classpath 'com.android.tools.build:gradle:2.1.0'
then go to your app project > app > graddle > graddlewrapper.properties and add
distributionUrl=https://services.gradle.org/distributions/gradle-2.10-all.zip
4.- change your compile compileSdkVersion to 24 and your buildToolsVersion "24.0.2" (MAKE SURE YOUR DEPENDENCES ARE UP TO DATE WITH THE SDK)
Have fun
回答8:
Changing the kotlin-stdlib dependency from:
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:1.2.0"
to
implementation "org.jetbrains.kotlin:kotlin-stdlib:1.2.0"
fixed the error.
回答9:
Not specifically related to your question, but maybe can solve this problem for all that find themselves here while searching for that error.
For me was the problem with SVG file that I have imported into my project. One of the paths in XML has empty pathData and that was causing the crash on some devices like Pixel XL, Samsung Galaxy S7,...
So double check imported XML for an image if you are using SVG as your image source.