当前位置: 首页 > 知识库问答 >
问题:

TWA应用程序错误:java。lang.NoClassDefFoundError

慕容安易
2023-03-14

我正在把我的pwa网站改成twa,我遇到了一些麻烦。

当我尝试同步或构建项目时,我遇到以下错误:

失败:生成失败,出现异常。

  • 出了什么问题:java。lang.NoClassDefFoundError:

JAVAlang.NoClassDefFoundError(无错误消息)

我不熟悉android和java,有人能帮我吗?

我正在使用bubblewrap/cli我的gradle:

import groovy.xml.MarkupBuilder  // ERROR : Cannot resolve symbol 'MarkupBuilder'
 
apply plugin: 'com.android.application'

def twaManifest = [
    applicationId: 'br.com.estudoon.www.twa',
    hostName: 'www.estudoon.com.br',
    launchUrl: '/login', 
    name: 'Estudoon!',
    launcherName: 'OON!', 
    themeColor: '#000000', 
    navigationColor: '#000000', 
    navigationColorDark: '#000000', 
    navigationDividerColor: '#000000', 
    navigationDividerColorDark: '#000000', 
    backgroundColor: '#FFFFFF', 
    enableNotifications: true, 
    shortcuts: [],
    splashScreenFadeOutDuration: 300,
    generatorApp: 'bubblewrap-cli', // Application that generated the Android Project
    fallbackType: 'customtabs',
    enableSiteSettingsShortcut: 'true',
    orientation: 'any',
]

android {
    compileSdkVersion 30
    defaultConfig {
        applicationId "br.com.estudoon.www.twa"
        minSdkVersion 19
        targetSdkVersion 30
        versionCode 1
        versionName "1"

        resValue "string", "appName", twaManifest.name

        resValue "string", "launcherName", twaManifest.launcherName

        def launchUrl = "https://" + twaManifest.hostName + twaManifest.launchUrl
        resValue "string", "launchUrl", launchUrl

        
            resValue "string", "webManifestUrl", 'https://www.estudoon.com.br/manifest.json'
        
        resValue "string", "hostName", twaManifest.hostName
twa#set_up_digital_asset_links_in_an_android_app
        resValue "string", "assetStatements",
                '[{ \\"relation\\": [\\"delegate_permission/common.handle_all_urls\\"],' +
                        '\\"target\\": {\\"namespace\\": \\"web\\", \\"site\\": \\"https://' +
                        twaManifest.hostName + '\\"}}]'

        resValue "color", "colorPrimary", twaManifest.themeColor

        resValue "color", "navigationColor", twaManifest.navigationColor

        resValue "color", "navigationColorDark", twaManifest.navigationColorDark

        resValue "color", "navigationDividerColor", twaManifest.navigationDividerColor

        resValue "color", "navigationDividerColorDark", twaManifest.navigationDividerColorDark

        resValue "color", "backgroundColor", twaManifest.backgroundColor

        resValue "string", "providerAuthority", twaManifest.applicationId + '.fileprovider'

        resValue "bool", "enableNotification", twaManifest.enableNotifications.toString()

        twaManifest.shortcuts.eachWithIndex { shortcut, index ->
            resValue "string", "shortcut_name_$index", "$shortcut.name"
            resValue "string", "shortcut_short_name_$index", "$shortcut.short_name"
        }
        resValue "integer", "splashScreenFadeOutDuration", twaManifest.splashScreenFadeOutDuration.toString()

        resValue "string", "generatorApp", twaManifest.generatorApp

        resValue "string", "fallbackType", twaManifest.fallbackType

        resValue "bool", "enableSiteSettingsShortcut", twaManifest.enableSiteSettingsShortcut
        resValue "string", "orientation", twaManifest.orientation
    }
    buildTypes {
        release {
            minifyEnabled true
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    lintOptions {
        checkReleaseBuilds false
    }
}

task generateShorcutsFile {
    assert twaManifest.shortcuts.size() < 5, "You can have at most 4 shortcuts."
    twaManifest.shortcuts.eachWithIndex { s, i ->
        assert s.name != null, 'Missing `name` in shortcut #' + i
        assert s.short_name != null, 'Missing `short_name` in shortcut #' + i
        assert s.url != null, 'Missing `icon` in shortcut #' + i
        assert s.icon != null, 'Missing `url` in shortcut #' + i
    }

    def shortcutsFile = new File("$projectDir/src/main/res/xml", "shortcuts.xml")

    def xmlWriter = new StringWriter()
    def xmlMarkup = new MarkupBuilder(new IndentPrinter(xmlWriter, "    ", true))

    xmlMarkup
        .'shortcuts'('xmlns:android': 'http://schemas.android.com/apk/res/android') {
            twaManifest.shortcuts.eachWithIndex { s, i ->
                'shortcut'(
                        'android:shortcutId': 'shortcut' + i,
                        'android:enabled': 'true',
                        'android:icon': '@drawable/' + s.icon,
                        'android:shortcutShortLabel': '@string/shortcut_short_name_' + i,
                        'android:shortcutLongLabel': '@string/shortcut_name_' + i) {
                    'intent'(
                            'android:action': 'android.intent.action.MAIN',
                            'android:targetPackage': twaManifest.applicationId,
                            'android:targetClass': twaManifest.applicationId + '.LauncherActivity',
                            'android:data': s.url)
                    'categories'('android:name': 'android.intent.category.LAUNCHER')
                }
            }
        }
    shortcutsFile.text = xmlWriter.toString() + '\n'
}

preBuild.dependsOn(generateShorcutsFile)

repositories {
    
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
        implementation 'com.google.androidbrowserhelper:androidbrowserhelper:2.2.0'
    
}

编辑:我在任何项目中都遇到了相同的错误,即使是android Studio中的bult。已经重新安装了android Studio、XAMPP、java和node。

共有1个答案

司空默
2023-03-14

对于无法解析符号MarkupBuilder:将groovy类路径添加到构建中。如果使用的是gradle 7

buildscript {
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:7.0.0'
        classpath 'org.codehaus.groovy:groovy-xml:3.0.8'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}
allprojects {
    repositories {
        google()
        mavenCentral()
    }
}
task clean(type: Delete) {
    delete rootProject.buildDir
}

 类似资料: