【问题标题】:AAPT2 error: check logs for details(Build failed)AAPT2 错误:检查日志以获取详细信息(构建失败)
【发布时间】:2018-10-13 22:29:19
【问题描述】:

我只是支持我的旧项目,因为我一直没有处理它,我发现很多错误是 gradle 中的构建错误,因为我使用编译而不是实现以及我试图解决的许多其他过程这个错误很多,但我失败了as this my window error 那是我无法识别,因为我也使用了来自 github 的旧库

这是 myGradle (build.gradle(Project:Waiterer))

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.2'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

这是 build.gradle(Module:app)

apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    buildToolsVersion '27.0.3'
    defaultConfig {
        applicationId "abtech.waiteriano.com.waitrer"
        minSdkVersion 18
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    implementation project(':jtds-1.3.1')
    implementation project(':library')
    implementation project(':librarySV')
    implementation 'com.android.support:support-v4:25.2.0'
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support:design:25.3.1'
    implementation 'com.roughike:bottom-bar:1.3.9'
    implementation 'com.android.support:recyclerview-v7:25.2.0'
    implementation 'com.android.support.constraint:constraint-layout:1.0.0-alpha8'
    implementation 'com.github.clans:fab:1.6.2'
    implementation 'de.hdodenhof:circleimageview:1.3.0'
    implementation 'com.android.support:cardview-v7:25.3.1'
    testImplementation 'junit:junit:4.12'
    implementation "com.android.support:gridlayout-v7:23.1.1"
}

这是我使用的第一个 gradle 库 build.gradle(模块:库)

apply plugin: 'com.android.library'

android {
    compileSdkVersion 23
    buildToolsVersion '27.0.3'

    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:23.1.1'
}

这是我使用的第二个库 build.gradle(Module:librarySV)

apply plugin: 'com.android.library'
apply plugin: 'com.novoda.bintray-release'

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.novoda:bintray-release:0.8.1'
    }
}

android {
    compileSdkVersion 23
    buildToolsVersion '25.0.0'

    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 23
        versionCode 1
        versionName "1.4.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:23.1.1'
    implementation 'com.android.support:design:23.1.1'
}

publish {
    userOrg = 'miguelcatalan'
    groupId = 'com.miguelcatalan'
    artifactId = 'materialsearchview'
    publishVersion = '1.4.0'
    desc = 'Cute library to implement SearchView in a Material Design Approach'
    website = 'https://github.com/MiguelCatalan/MaterialSearchView'
}

希望这可以足够清楚如果有任何不清楚的地方告诉我 请注意:我没有使用 API 我使用 JDBC JTDS 连接从数据库中检索数据

【问题讨论】:

  • 遗憾的是,这信息还不够。你的项目在 github 上吗?如果您无法共享您的项目,请转到您的项目目录并运行“gradlew clean assembleDebug”并编辑帖子以包含输出。它应该包含来自 AAPT2 的错误
  • 非常感谢@Izabela Orlowska 我在 GutHub 上分享了项目,我会发送给你
  • 听起来不错 :) 可能需要进行一些小的调整,因为 AAPT2 比 AAPT1 严格得多,并且可以及早发现大多数错误,而不是允许运行时问题
  • 提取文件时出错。你能把它拉上拉链吗?或者放在 bitbucket/github 上,这样我就可以看到源代码(dropbox 不会显示某些文件的内容)
  • 它已经压缩了,我会尝试,但它在 bitbucket/github 中

标签: android gradle build


【解决方案1】:

问题是开发人员仍然对新 AS 感到不舒服。显示错误的方式已更改(现在很奇怪)。

首先在构建错误中向下滚动。如果您看到错误,请单击以展开它。它很可能会向您显示错误。

第二次如果这不起作用(就像我在数据绑定中遇到的那样,没有显示错误)

然后尝试使用 debug 或 stacktrace 构建

前往

文件 > 设置 > 构建、执行、部署 > 编译器

像这样添加(添加--stacktrace 或--debug),它将记录异常。您可以查看导致问题的原因。

【讨论】:

  • 很好的解释!我想在第一张图片中添加它,在您看到构建窗口的地方有一个绿色的锤子图标,在它下面有一个图标可以将视图从项目符号更改为实际的构建日志。该切换图标是隐藏最有用信息的地方。
【解决方案2】:

好的,问题出在应用模块中的 AndroidManifest 上:

    <activity android:name=".Main2Activity">
        <service
            android:name="SoftKeyboard"
            android:permission="android.permission.BIND_INPUT_METHOD"
            tools:ignore="WrongManifestParent">
            <intent-filter>
                <action android:name="android.view.InputMethod" />
            </intent-filter>
            <meta-data
                android:name="android.view.im"
                android:resource="@xml/method" />
        </service>

        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

根据documentation,“服务”元素必须嵌套在“应用程序”而不是“活动”下。所以把那部分代码改成:

    <activity android:name=".Main2Activity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <service
        android:name="SoftKeyboard"
        android:permission="android.permission.BIND_INPUT_METHOD"
        tools:ignore="WrongManifestParent">
        <intent-filter>
            <action android:name="android.view.InputMethod" />
        </intent-filter>
        <meta-data
            android:name="android.view.im"
            android:resource="@xml/method" />
    </service>

这将解决您从 AAPT2 收到的错误。为了使您的项目成功构建,您还需要按照here 的描述更新您的依赖项。如果你两者都做,一切都应该正确构建。 :)

【讨论】:

  • 非常感谢,我发现了服务错误,但我没有认识到服务器的语法......它现在工作了!!!现在好了!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-04-11
  • 1970-01-01
  • 2019-08-04
  • 1970-01-01
相关资源
最近更新 更多