安卓工作室-APT:错误:文件无法使用PNG图像进行编译



我在Ubuntu linux上工作,最近我退出了我的项目,开始在Win10上工作。

从现在起,我无法构建/运行我的应用程序。resources文件夹中的那些PNG文件一定有问题。

这是尝试构建应用程序时的错误输出

Executing tasks: [:app:assembleDebug] in project C:UsersPszDocumentsAndroid-ChatRoom-Client
> Task :app:preBuild UP-TO-DATE
> Task :app:preDebugBuild UP-TO-DATE
> Task :app:compileDebugAidl NO-SOURCE
> Task :app:generateDebugBuildConfig UP-TO-DATE
> Task :app:compileDebugRenderscript NO-SOURCE
> Task :app:javaPreCompileDebug UP-TO-DATE
> Task :app:generateDebugResValues UP-TO-DATE
> Task :app:generateDebugResources UP-TO-DATE
> Task :app:createDebugCompatibleScreenManifests UP-TO-DATE
> Task :app:extractDeepLinksDebug UP-TO-DATE
> Task :app:processDebugManifest UP-TO-DATE
> Task :app:mergeDebugShaders UP-TO-DATE
> Task :app:compileDebugShaders NO-SOURCE
> Task :app:generateDebugAssets UP-TO-DATE
> Task :app:mergeDebugAssets UP-TO-DATE
> Task :app:processDebugJavaRes NO-SOURCE
> Task :app:mergeDebugResources FAILED
AGPBI: {"kind":"error","text":"Android resource compilation failed","sources":[{"file":"C:\Users\Psz\Documents\Android-ChatRoom-Client\app\build\generated\res\pngs\debug\drawable-ldpi\ic_launcher_background.png"}],"original":"C:\Users\Psz\Documents\Android-ChatRoom-Client\app\build\generated\res\pngs\debug\drawable-ldpi\ic_launcher_background.png: AAPT: error: file failed to compile.n    ","tool":"AAPT"}
AGPBI: {"kind":"error","text":"Android resource compilation failed","sources":[{"file":"C:\Users\Psz\Documents\Android-ChatRoom-Client\app\build\generated\res\pngs\debug\drawable-xhdpi\ic_greensky_background.png"}],"original":"C:\Users\Psz\Documents\Android-ChatRoom-Client\app\build\generated\res\pngs\debug\drawable-xhdpi\ic_greensky_background.png: AAPT: error: file failed to compile.n    ","tool":"AAPT"}
AGPBI: {"kind":"error","text":"Android resource compilation failed","sources":[{"file":"C:\Users\Psz\Documents\Android-ChatRoom-Client\app\build\generated\res\pngs\debug\drawable-hdpi\ic_launcher_background.png"}],"original":"C:\Users\Psz\Documents\Android-ChatRoom-Client\app\build\generated\res\pngs\debug\drawable-hdpi\ic_launcher_background.png: AAPT: error: file failed to compile.n    ","tool":"AAPT"}
AGPBI: {"kind":"error","text":"Android resource compilation failed","sources":[{"file":"C:\Users\Psz\Documents\Android-ChatRoom-Client\app\build\generated\res\pngs\debug\drawable-mdpi\ic_greensky_background.png"}],"original":"C:\Users\Psz\Documents\Android-ChatRoom-Client\app\build\generated\res\pngs\debug\drawable-mdpi\ic_greensky_background.png: AAPT: error: file failed to compile.n    ","tool":"AAPT"}
AGPBI: {"kind":"error","text":"Android resource compilation failed","sources":[{"file":"C:\Users\Psz\Documents\Android-ChatRoom-Client\app\build\generated\res\pngs\debug\drawable-mdpi\ic_launcher_background.png"}],"original":"C:\Users\Psz\Documents\Android-ChatRoom-Client\app\build\generated\res\pngs\debug\drawable-mdpi\ic_launcher_background.png: AAPT: error: file failed to compile.n    ","tool":"AAPT"}
AGPBI: {"kind":"error","text":"Android resource compilation failed","sources":[{"file":"C:\Users\Psz\Documents\Android-ChatRoom-Client\app\build\generated\res\pngs\debug\drawable-xxhdpi\ic_greensky_background.png"}],"original":"C:\Users\Psz\Documents\Android-ChatRoom-Client\app\build\generated\res\pngs\debug\drawable-xxhdpi\ic_greensky_background.png: AAPT: error: file failed to compile.n    ","tool":"AAPT"}
AGPBI: {"kind":"error","text":"Android resource compilation failed","sources":[{"file":"C:\Users\Psz\Documents\Android-ChatRoom-Client\app\build\generated\res\pngs\debug\drawable-hdpi\ic_greensky_background.png"}],"original":"C:\Users\Psz\Documents\Android-ChatRoom-Client\app\build\generated\res\pngs\debug\drawable-hdpi\ic_greensky_background.png: AAPT: error: file failed to compile.n    ","tool":"AAPT"}
AGPBI: {"kind":"error","text":"Android resource compilation failed","sources":[{"file":"C:\Users\Psz\Documents\Android-ChatRoom-Client\app\build\generated\res\pngs\debug\drawable-ldpi\ic_greensky_background.png"}],"original":"C:\Users\Psz\Documents\Android-ChatRoom-Client\app\build\generated\res\pngs\debug\drawable-ldpi\ic_greensky_background.png: AAPT: error: file failed to compile.n    ","tool":"AAPT"}
> Task :app:mergeDebugJavaResource
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:mergeDebugResources'.
> Multiple task action failures occurred:
> A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
> Android resource compilation failed
C:UsersPszDocumentsAndroid-ChatRoom-Clientappbuildgeneratedrespngsdebugdrawable-ldpiic_greensky_background.png: AAPT: error: file failed to compile.

> A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
> Android resource compilation failed
C:UsersPszDocumentsAndroid-ChatRoom-Clientappbuildgeneratedrespngsdebugdrawable-mdpiic_greensky_background.png: AAPT: error: file failed to compile.

> A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
> Android resource compilation failed
C:UsersPszDocumentsAndroid-ChatRoom-Clientappbuildgeneratedrespngsdebugdrawable-ldpiic_launcher_background.png: AAPT: error: file failed to compile.

> A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
> Android resource compilation failed
C:UsersPszDocumentsAndroid-ChatRoom-Clientappbuildgeneratedrespngsdebugdrawable-hdpiic_greensky_background.png: AAPT: error: file failed to compile.

> A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
> Android resource compilation failed
C:UsersPszDocumentsAndroid-ChatRoom-Clientappbuildgeneratedrespngsdebugdrawable-mdpiic_launcher_background.png: AAPT: error: file failed to compile.

> A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
> Android resource compilation failed
C:UsersPszDocumentsAndroid-ChatRoom-Clientappbuildgeneratedrespngsdebugdrawable-xhdpiic_greensky_background.png: AAPT: error: file failed to compile.

> A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
> Android resource compilation failed
C:UsersPszDocumentsAndroid-ChatRoom-Clientappbuildgeneratedrespngsdebugdrawable-hdpiic_launcher_background.png: AAPT: error: file failed to compile.

> A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
> Android resource compilation failed
C:UsersPszDocumentsAndroid-ChatRoom-Clientappbuildgeneratedrespngsdebugdrawable-xxhdpiic_greensky_background.png: AAPT: error: file failed to compile.

* 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 1s
10 actionable tasks: 2 executed, 8 up-to-date

build.gradle(:app(文件:

apply plugin: 'com.android.application'
android {
compileSdkVersion 30
configurations.all {
resolutionStrategy.eachDependency{
DependencyResolveDetails details ->
def requested = details.requested
if (requested.group=="com.android.support"){
if (!requested.name.startsWith("multidex")){
details.useVersion("26.+")
}
}
}
}
buildToolsVersion "30.0.2"
defaultConfig {
applicationId "com.myname.greenskychatroom"
minSdkVersion 16
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.2.1'
implementation 'androidx.annotation:annotation:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.1'
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
implementation files('libs/json-simple-1.1.jar')
testImplementation 'junit:junit:4.13'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}

我不知道是什么原因造成的。我再次清理了缓存、删除和拉取项目。此外,我在网上找不到解决方案。

更新发现Linux(Ubuntu(上的Android Studio运行良好,事实上,此错误仅发生在Windows的Android Studio上。。

我遇到了类似的问题,根本原因是JPEG文件的扩展名是PNG。一旦我修复了文件扩展名,AAPT很高兴。

如果某些文件已加密,AAPT可能无法正常工作。请检查与编译错误相关的文件是否已加密。在您的情况下,这些是PNG文件。

在我的案例中,我试图使用从whatsapp下载的一些png图像,这些图像经过了加密。

要修复它,请执行以下步骤:

1-开放式油漆2-打开您的图像3保存

你已经准备好出发了!

如果是expo应用程序,请删除您刚才添加的png资产。你可以将它们重命名为jpg,这将适用于

我也有同样的错误。尝试了一切,包括拔出我自己的耳朵,但都没用。然后有人提到运行Android Studio作为admin可以解决这个问题。。。因此,它与write access问题有关。答对 了试试这个:

In windows go to Ransomware protection and disable it!

然后尝试再次构建。如果有效,则使用Allow an app through Controlled folder access赋予gradle访问权限。然后再次启用勒索软件保护。

在Windows中,尽量将您的项目保存在与Windows不同的驱动器(C驱动器(中。您可以使用D驱动器并尝试保持路径较短(例如D:\Projects\XyzProject(。这可能会解决您的问题。

我面临同样的问题,并已解决。此错误是由于windows安全性,请选择导致问题的文件属性并取消阻止。

这个问题不过是图像文件扩展名的问题。我的图像是jpeg格式的,但我把它保存在我的可绘制文件夹中作为png格式。这就是为什么这场冲突是由android引发的。

我只是将我的图像转换为png版本,并在我的android项目中实现,并删除了旧的jpg图像。然后android正常工作。

相关内容

  • 没有找到相关文章

最新更新