gpt4 book ai didi

android-studio - javah错误:gradle和Android Studio不存在该包

转载 作者:行者123 更新时间:2023-12-03 06:08:24 25 4
gpt4 key购买 nike

最近,在编译Java源代码以产生C++头文件时遇到错误:javah为某些文件吐出package does not exist错误。

tl; dr: javah适用于Java源代码,但不适用于其他Java源代码–导入子句非常接近。 gradle不处理某些库,但即使已处理的程序包也被标记为丢失。

我不知道为什么javah会开始吐出该错误,因为它直到最近都运行良好,而且我没有更改任何特殊内容。我在Android Studio的gradle中使用gradle-wrapper。我最近将包装器的发行版从2.2.1更新到了2.10,但是我不认为这就是javah现在失败的原因。

根据日志和当前文件,javah不能从我正在使用的库中找到软件包,因为它可以编译ClassB而不是ClassA

让我们举两个例子:com.batch.androidcom.adjust.sdk

  • com.batch.android是否通过gradle处理,因此其jars 在我的build/intermediates/exploded-aar文件夹中(com.batch.android/batch-sdk/1.5.3/jars/classes.jar和com.batch.android/batch- sdk / 1.5.3 / jars / libs / batch.jar)
  • com.adjust.sdk不会由gradle处理,因此在我的build / intermediates / exploded-aar
  • 中,其jars 不是
  • 都在我的〜/ .gradle / cache /文件夹中
  • 两个软件包均因javah缺少而失败
  • 这两个软件包都不从ClassAClassB Java文件
  • 导入

    谢谢你的帮助!

    gradle日志(抱歉,它很长):
    Executing tasks: [:app:clean, :app:generateDevAmazonDebugSources, :app:generateDevAmazonDebugAndroidTestSources, :app:mockableAndroidJar, :app:prepareDevAmazonDebugUnitTestDependencies,     :app:assembleDevAmazonDebug]

    Configuration on demand is an incubating feature.
    :buildSrc:compileJava UP-TO-DATE
    :buildSrc:compileGroovy UP-TO-DATE
    :buildSrc:processResources UP-TO-DATE
    :buildSrc:classes UP-TO-DATE
    :buildSrc:jar UP-TO-DATE
    :buildSrc:assemble UP-TO-DATE
    :buildSrc:compileTestJava UP-TO-DATE
    :buildSrc:compileTestGroovy UP-TO-DATE
    :buildSrc:processTestResources UP-TO-DATE
    :buildSrc:testClasses UP-TO-DATE
    :buildSrc:test UP-TO-DATE
    :buildSrc:check UP-TO-DATE
    :buildSrc:build UP-TO-DATE
    Generating assets binaries
    Incremental java compilation is an incubating feature.
    Cleaning project...
    :app:clean
    :app:processAssets
    :app:copyFiles
    :app:preBuild
    :app:preDevAmazonDebugBuild
    :app:checkDevAmazonDebugManifest
    :app:preDevAmazonReleaseBuild
    :app:preDevGoogleDebugBuild
    :app:preDevGoogleReleaseBuild
    :app:preProdAmazonDebugBuild
    :app:preProdAmazonReleaseBuild
    :app:preProdGoogleDebugBuild
    :app:preProdGoogleReleaseBuild
    :app:prepareComAndroidSupportAppcompatV72311Library
    :app:prepareComAndroidSupportCardviewV72320Library
    :app:prepareComAndroidSupportMediarouterV72220Library
    :app:prepareComAndroidSupportMultidex100Library
    :app:prepareComAndroidSupportRecyclerviewV72311Library
    :app:prepareComAndroidSupportSupportV42320Library
    :app:prepareComBatchAndroidBatchSdk153Library
    :app:prepareComCrashlyticsSdkAndroidAnswers136Library
    :app:prepareComCrashlyticsSdkAndroidBeta114Library
    :app:prepareComCrashlyticsSdkAndroidCrashlytics255Library
    :app:prepareComCrashlyticsSdkAndroidCrashlyticsCore238Library
    :app:prepareComCrashlyticsSdkAndroidCrashlyticsNdk112Library
    :app:prepareComFacebookAndroidFacebookAndroidSdk4101Library
    :app:prepareComGoogleAndroidExoplayerExoplayerR142Library
    :app:prepareComGoogleAndroidGmsPlayServices780Library
    :app:prepareComGoogleAndroidGmsPlayServicesAds780Library
    :app:prepareComGoogleAndroidGmsPlayServicesAnalytics780Library
    :app:prepareComGoogleAndroidGmsPlayServicesAppindexing780Library
    :app:prepareComGoogleAndroidGmsPlayServicesAppinvite780Library
    :app:prepareComGoogleAndroidGmsPlayServicesAppstate780Library
    :app:prepareComGoogleAndroidGmsPlayServicesBase780Library
    :app:prepareComGoogleAndroidGmsPlayServicesCast780Library
    :app:prepareComGoogleAndroidGmsPlayServicesDrive780Library
    :app:prepareComGoogleAndroidGmsPlayServicesFitness780Library
    :app:prepareComGoogleAndroidGmsPlayServicesGames780Library
    :app:prepareComGoogleAndroidGmsPlayServicesGcm780Library
    :app:prepareComGoogleAndroidGmsPlayServicesIdentity780Library
    :app:prepareComGoogleAndroidGmsPlayServicesLocation780Library
    :app:prepareComGoogleAndroidGmsPlayServicesMaps780Library
    :app:prepareComGoogleAndroidGmsPlayServicesNearby780Library
    :app:prepareComGoogleAndroidGmsPlayServicesPanorama780Library
    :app:prepareComGoogleAndroidGmsPlayServicesPlus780Library
    :app:prepareComGoogleAndroidGmsPlayServicesSafetynet780Library
    :app:prepareComGoogleAndroidGmsPlayServicesVision780Library
    :app:prepareComGoogleAndroidGmsPlayServicesWallet780Library
    :app:prepareComGoogleAndroidGmsPlayServicesWearable780Library
    :app:prepareComMopubMopubSdk440Library
    :app:prepareComZendeskBelvedere1011Library
    :app:prepareComZendeskSdk1512Library
    :app:prepareComZendeskSdkProviders1512Library
    :app:prepareIoBranchSdkAndroidLibrary1112Library
    :app:prepareIoFabricSdkAndroidFabric1310Library
    :app:prepareDevAmazonDebugDependencies
    :app:compileDevAmazonDebugAidl
    :app:compileDevAmazonDebugRenderscript
    :app:generateDevAmazonDebugBuildConfig
    :app:generateDevAmazonDebugAssets UP-TO-DATE
    :app:mergeDevAmazonDebugAssets
    :app:processDevAmazonDebugManifest
    :app:fabricGenerateResourcesDevAmazonDebug
    :app:generateDevAmazonDebugResValues UP-TO-DATE
    :app:processDevAmazonDebugGoogleServices
    :app:generateDevAmazonDebugResources
    :app:mergeDevAmazonDebugResources
    :app:processDevAmazonDebugResources
    :app:generateDevAmazonDebugSources
    :app:preDevAmazonDebugAndroidTestBuild
    :app:prepareDevAmazonDebugAndroidTestDependencies
    :app:compileDevAmazonDebugAndroidTestAidl
    :app:processDevAmazonDebugAndroidTestManifest
    :app:compileDevAmazonDebugAndroidTestRenderscript
    :app:generateDevAmazonDebugAndroidTestBuildConfig
    :app:generateDevAmazonDebugAndroidTestAssets UP-TO-DATE
    :app:mergeDevAmazonDebugAndroidTestAssets
    :app:generateDevAmazonDebugAndroidTestResValues UP-TO-DATE
    :app:generateDevAmazonDebugAndroidTestResources
    :app:mergeDevAmazonDebugAndroidTestResources
    :app:processDevAmazonDebugAndroidTestResources
    :app:generateDevAmazonDebugAndroidTestSources
    :app:mockableAndroidJar UP-TO-DATE
    :app:preDevAmazonDebugUnitTestBuild
    :app:prepareDevAmazonDebugUnitTestDependencies
    :app:javahBuild_ClassA
    :app:javahBuild_ClassB
    Error: package com.adjust.sdk does not exist
    Error: package com.adjust.sdk does not exist
    Error: package com.amazon.ags.api does not exist
    Error: package com.batch.android does not exist
    Error: package com.batch.android does not exist
    Error: package com.crashlytics.android does not exist
    Error: package com.crashlytics.android.answers does not exist
    Error: package com.crashlytics.android.answers does not exist
    Error: package com.crashlytics.android.answers does not exist
    Error: package com.mopub.common does not exist
    Error: package com.zendesk.sdk.feedback.impl does not exist
    Error: package com.zendesk.sdk.model.access does not exist
    Error: package com.zendesk.sdk.model.access does not exist
    Error: package com.zendesk.sdk.model.push does not exist
    Error: package com.zendesk.sdk.network.impl does not exist
    Error: package com.zendesk.sdk.network.impl does not exist
    Error: package com.zendesk.sdk.network.impl does not exist
    Error: package com.zendesk.sdk.network.impl does not exist
    Error: package com.zendesk.sdk.network.impl does not exist
    Error: package com.zendesk.sdk.requests does not exist
    Error: package com.zendesk.sdk.storage does not exist
    Error: package com.zendesk.sdk.support does not exist
    Error: package com.zendesk.service does not exist
    Error: package com.zendesk.service does not exist
    Error: package org.joda.time does not exist
    Error: package org.joda.time does not exist
    Error: package org.joda.time does not exist
    Error: package org.joda.time does not exist
    Error: package org.joda.time.format does not exist
    Error: package org.joda.time.format does not exist
    Error: package io.branch.indexing does not exist
    Error: package io.branch.referral does not exist
    Error: package io.branch.referral does not exist
    Error: package io.branch.referral does not exist
    Error: package io.branch.referral.util does not exist
    Error: package io.branch.referral.util does not exist
    Error: package com.adjust.sdk does not exist
    Error: package com.amazon.ags.api does not exist
    Error: package com.amazon.ags.api does not exist
    Error: package com.amazon.ags.api does not exist
    Error: package com.amazon.ags.api does not exist
    Error: package com.applovin.sdk does not exist
    Error: package com.batch.android does not exist
    Error: package com.crashlytics.android does not exist
    Error: package com.crashlytics.android.ndk does not exist
    Error: package io.branch.referral does not exist
    Error: package io.branch.referral does not exist
    Error: package io.fabric.sdk.android does not exist
    Error: package com.google.android.gms.analytics does not exist
    Error: package com.google.android.gms.analytics does not exist
    Error: package com.google.android.gms.analytics does not exist
    Error: package com.google.android.gms.ads.identifier does not exist
    Error: package com.google.android.gms.common does not exist
    Error: package com.mopub.common does not exist
    Error: package com.mopub.common does not exist
    Error: cannot find symbol
    symbol: class MoPubErrorCode
    location: package com.mopub.mobileads
    Error: cannot find symbol
    symbol: class MoPubRewardedVideoListener
    location: package com.mopub.mobileads
    Error: package com.chartboost.sdk does not exist
    Error: package com.adjust.sdk does not exist
    Error: package com.adjust.sdk does not exist
    Error: package com.adjust.sdk does not exist
    Error: package com.adjust.sdk does not exist
    Error: cannot find symbol
    symbol: class BaseZendeskFeedbackConfiguration
    location: class my.super.project.Renderer
    Error: cannot find symbol
    symbol: class BuildConfig
    location: package my.super.project
    Error: cannot find symbol
    symbol: class Tracker
    location: class my.super.project.Main
    Error: ';' expected
    Error: package com.facebook does not exist
    Error: package com.facebook does not exist
    Error: package com.facebook does not exist
    Error: package com.facebook does not exist
    Error: package com.facebook does not exist
    Error: package com.facebook does not exist
    Error: package com.facebook does not exist
    Error: package com.facebook does not exist
    Error: package com.facebook does not exist
    Error: package com.facebook does not exist
    Error: package com.facebook.appevents does not exist
    Error: package com.facebook.login does not exist
    Error: package com.facebook.login does not exist
    Error: package com.facebook.share.model does not exist
    Error: package com.facebook.share.model does not exist
    Error: package com.facebook.share.model does not exist
    Error: package com.facebook.share.widget does not exist
    Error: package com.facebook.share.widget does not exist
    Error: package com.facebook.share.widget does not exist
    Error: package twitter4j does not exist
    Error: package twitter4j does not exist
    Error: package twitter4j does not exist
    Error: package twitter4j does not exist
    Error: package twitter4j does not exist
    Error: package twitter4j does not exist
    Error: package twitter4j does not exist
    Error: package twitter4j does not exist
    Error: package twitter4j.auth does not exist
    Error: cannot find symbol
    symbol: class R
    location: package my.super.project
    Error: cannot find symbol
    symbol: class AmazonGamesClient
    location: class my.super.project.Main
    Error: cannot find symbol
    symbol: class MoPubRewardedVideoListener
    location: class my.super.project.Main
    Error: cannot find symbol
    symbol: class ChartBoostDelegate
    location: class my.super.project.Main
    Error: cannot find symbol
    symbol: class CallbackManager
    location: class my.super.project.ClassA
    Error: cannot find symbol
    symbol: class ProfileTracker
    location: class my.super.project.ClassA

    FAILED

    FAILURE: Build failed with an exception.

    我的build.gradle具有以下任务:
    android {
    <snip>
    ['Main', 'Renderer', 'ClassA', 'ClassB'].each {
    def targetName ->
    tasks.create(name: "javahBuild_$targetName", type: Exec) {
    Properties properties = new Properties()
    properties.load(project.rootProject.file('local.properties').newDataInputStream())
    String sdkDir = properties.getProperty('sdk.dir')
    String flavorFolder = getCurrentFlavorFolder()
    commandLine 'javah', '-classpath', "libs/:src/main/java/:$sdkDir/platforms/android-23/android.jar:build/intermediates/classes/$flavorFolder/$config:$sdkDir/platforms/android-23/optional/org.apache.http.legacy.jar/:$config/", '-d', 'src/main/jni/Main/', "my.super.project.${targetName}"
    }
    }

    task javahBuildAll(dependsOn: tasks.matching { Task task -> task.name.startsWith("javahBuild_") })

    tasks.withType(JavaCompile) {
    compileTask -> compileTask.dependsOn javahBuildAll
    }
    }

    dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')

    compile('com.crashlytics.sdk.android:crashlytics:2.5.5@aar') {
    transitive = true;
    }
    compile('com.crashlytics.sdk.android:crashlytics-ndk:1.1.2@aar') {
    transitive = true
    }
    compile('com.mopub:mopub-sdk:4.4.0@aar') {
    transitive = true
    }

    compile group: 'com.zendesk', name: 'sdk', version: '1.5.1.2'

    compile('com.android.support:multidex:1.0.0')
    compile('com.google.android.gms:play-services:7.8.0')
    compile('com.google.android.gms:play-services-analytics:7.8.0')
    compile('com.google.android.gms:play-services-gcm:7.8.0')
    compile('com.android.support:appcompat-v7:23.1.0')
    compile('com.android.support:support-v4:23.1.0')
    compile('com.facebook.android:facebook-android-sdk:4.10.+')
    compile('io.branch.sdk.android:library:1.+')
    compile('com.batch.android:batch-sdk:1.5+')
    compile('com.adjust.sdk:adjust-android:4.2.3')
    compile('joda-time:joda-time:2.9.2')
    }

    最佳答案

    好的,它不明白为什么会出现这些错误,但我只是意识到我可以忽略它们,因为C++头文件仍在生成。

    因此,我决定修改javah gradle任务以忽略错误,并将这些错误写入专用的日志文件。我添加了以下行:

    errorOutput = project.file("build/javah_error_${targetName}.log").newDataOutputStream()
    ignoreExitValue = true

    我的 javah任务现在看起来像这样:
    ['Main', 'Renderer', 'ClassA', 'ClassB'].each {
    def targetName ->
    tasks.create(name: "javahBuild_$targetName", type: Exec) {
    Properties properties = new Properties()
    properties.load(project.rootProject.file('local.properties').newDataInputStream())
    String sdkDir = properties.getProperty('sdk.dir')
    String flavorFolder = getCurrentFlavorFolder()
    errorOutput = project.file("build/javah_error_${targetName}.log").newDataOutputStream()
    ignoreExitValue = true
    commandLine 'javah', '-classpath', "libs/:src/main/java/:$sdkDir/platforms/android-23/android.jar:build/intermediates/classes/$flavorFolder/$config:$sdkDir/platforms/android-23/optional/org.apache.http.legacy.jar/:$config/", '-d', 'src/main/jni/Main/', "my.super.project.${targetName}"
    }
    }

    关于android-studio - javah错误:gradle和Android Studio不存在该包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36810430/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com