我在编译Java源代码时遇到错误,最近生成了C ++标题:javah
为某个文件吐出package does not exist
错误。
tl; dr: javah
适用于Java源代码但不适用于另一个源代码 - 哪些导入子句非常接近; gradle
不会处理某些库,但即使已处理的包的包也会被标记为丢失。
我不知道为什么javah已经开始吐出那个错误,因为它直到最近都运行良好并且我没有改变任何特殊的东西。我在Android Studio的gradle
中使用了gradle-wrapper
。我最近更新了包装器从2.2.1到2.10的分布,但我不认为这就是为什么javah现在失败了。
根据日志和当前文件,javah找不到我正在使用的库中的包,因为它编译ClassB
而不是ClassA
。
我们举两个例子:com.batch.android
和com.adjust.sdk
com.batch.android
库 会被gradle处理,因此我的build/intermediates/exploded-aar
文件夹中的jar (在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 / explosion-aar中的 >>
ClassA
和ClassB
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')
}
答案 0 :(得分:0)
好吧,它不明白我为什么会收到这些错误,但我只是意识到我可以忽略它们,因为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}"
}
}
答案 1 :(得分:0)
经过数小时的搜索,研究,反复试验等,我终于明白了。
javah
不见了,现在必须使用javac […] -h <destdir> […]
。
我的顶级build.gradle
中已经有以下代码段(不是app/
下的代码段!)到add javac
arguments…
tasks.withType(JavaCompile) {
options.compilerArgs << "-Xlint:all"
}
…和“只是”必须扩展。 (本节进入您在顶层allprojects {
中已经拥有的build.gradle
块,我将其放在repositories { […] }
块之后。)
在我的情况下,我只想创建.h
文件,而不希望在C代码中主动#include
个文件(因为我使用the RegisterNatives
method来注册我的函数),会很棘手,因为另外对此必须:
.h
文件仅出于自我检查的目的,我仅将javac -h <destdir>
选项添加到 all javac
调用中,创建每个任务的结果目录,然后在Midnight Commander中对其进行查看:
tasks.withType(JavaCompile) {
options.compilerArgs << "-Xlint:all"
options.getHeaderOutputDirectory().value(project.layout.buildDirectory.dir("headers/" + getName()))
}
(compilerArgs
的更改当然是从上面复制的。)