Home > Back-end >  Android studio error: FAILURE: Build failed with an exception
Android studio error: FAILURE: Build failed with an exception

Time:04-03

I'm developing a Flutter application in Dart using Android Studio, but when I run my code I get this error:

Launching lib\main.dart on AOSP on IA Emulator in debug mode...
Running Gradle task 'assembleDebug'...
Warning: Mapping new ns http://schemas.android.com/repository/android/common/02 to old ns http://schemas.android.com/repository/android/common/01
Warning: Mapping new ns http://schemas.android.com/repository/android/generic/02 to old ns http://schemas.android.com/repository/android/generic/01
Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/addon2/02 to old ns http://schemas.android.com/sdk/android/repo/addon2/01
Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/repository2/02 to old ns http://schemas.android.com/sdk/android/repo/repository2/01
Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/sys-img2/02 to old ns http://schemas.android.com/sdk/android/repo/sys-img2/01

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:processDebugResources'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
   > Android resource linking failed
     AAPT: ziparchive W 04-02 18:41:27 12204 10168 Zip: Entry at offset zero has invalid LFH signature 0
     error: failed to open APK: Invalid file.



* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 13s
Exception: Gradle task assembleDebug failed with exit code 1

What am I doing wrong and how to fix it?

EDIT: I didn't paste my code since that it is just for testing and I'm pretty sure that the problem is in Android Studio, by the way it is here:

import 'package:flutter/material.dart';

void main()
{
  runApp(App());
}


class App extends StatelessWidget
{

  const App({Key? key}) : super(key: key);

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context)
  {
    return MaterialApp(
      title: 'Tutorial 1',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: Homepage(),
    );
  }
}


class Homepage extends StatelessWidget
{

  @override
  Widget build(BuildContext context)
  {
    return Text('test');
  }
}

CodePudding user response:

Try:

Updating Gradle, Kotlin, Flutter, Dart

Updating Android Studio

Clearing Android Studio Cache

running "flutter pub get" in project terminal

Make sure use device with same API level to that mentioned in "app/build.grade"

Or check this https://www.geeksforgeeks.org/fix-execution-failed-appprocessdebugresources-in-android-studio/

CodePudding user response:

This problem may caused from xml code content:

1.Check activity`_main.xml` for all errors,

2. Fix all errors than rebuild by going to menu->build than click on 'Rebuild Project'

Or It can be solved by updating the compileSdkVersion and targetSdkVersion in build.gradle to latest one.

Resource

CodePudding user response:

In your gradle file (the one in the android/app directory), set your compileSdk version to 31. This works for me.

  • Related