Android Studio 3.2.1中是否有针对NDK错误的任何解决方案

时间:2019-01-07 11:34:49

标签: android c++ android-ndk

我试图运行成功构建的代码,但是当我尝试运行它时,出现错误!在StackOverflow中已经提出了类似的错误,但许多错误仍未得到解决。

这是错误:

Build command failed.
Error while executing process C:\AndroidStudio\Local\Android\SDK\ndk-bundle \ndk-build.cmd with arguments {NDK_PROJECT_PATH=null APP_BUILD_SCRIPT=D:\SuperAdventure\app\build\intermediates\ndk\debug\Android.mk APP_ABI=armeabi-v7a NDK_ALL_ABIS=armeabi-v7a NDK_DEBUG=1 APP_PLATFORM=android-16 NDK_OUT=D:/SuperAdventure/app/build/intermediates/ndkBuild/debug/obj NDK_LIBS_OUT=D:\SuperAdventure\app\build\intermediates\ndkBuild\debug\lib D:/SuperAdventure/app/build/intermediates/ndkBuild/debug/obj/local/armeabi-v7a/libplayer_shared.so}
 Android NDK: WARNING: Unsupported source file extensions in D:\SuperAdventure\app\build\intermediates\ndk\debug\Android.mk for module player_shared    
 Android NDK:   D:\SuperAdventure\app\src\main\jni\Android.mk D:\SuperAdventure\app\src\main\jni\Application.mk D:\SuperAdventure\app\src\main\jni\list.sh    
[armeabi-v7a] Compile++ thumb: player_shared <= main.cpp
D:\SuperAdventure\app\src\main\jni\main.cpp:1:10: fatal error: 'PTPAppDelegate.h' file not found
#include "PTPAppDelegate.h"  
1 error generated.
make: *** [D:/SuperAdventure/app/build/intermediates/ndkBuild/debug/obj/local/armeabi-v7a/objs-debug/player_shared/D_\SuperAdventure\app\src\main\jni\main.o] Error 1

这是我的build.gradle(module:app)

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    buildToolsVersion "28.0.3"

    defaultConfig {
        applicationId "com.sggame.superadventure"
        minSdkVersion 14
        targetSdkVersion 26
        multiDexEnabled true

        ndk {
            moduleName "player_shared"
        }
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'),  'proguard-rules.txt'
        }
    }
    externalNativeBuild {
        ndkBuild {
            path file('build/intermediates/ndk/debug/Android.mk')
        }
     }
}


dependencies {
    implementation 'com.google.android.gms:play-services:+'
    implementation files('libs/dagger-1.2.2.jar')
    implementation files('libs/javax.inject-1.jar')
    implementation files('libs/nineoldandroids-2.4.0.jar')
    implementation files('libs/support-v4-19.0.1.jar')
    implementation 'com.android.support:appcompat-v7:26.0.0'

}

main.cpp文件中充满错误:

#include "PTPAppDelegate.h"
#include "cocos2d.h"
#include "PTPConfig.h"
#include "models/PTModelController.h"
#include "PTPSettingsController.h"
#include "platform/android/jni/JniHelper.h"
#include <jni.h>
#include <android/log.h>
#include "models/PTModelScreen.h"
#include "models/PTModelAtlas.h"
#include "models/PTModelGeneralSettings.h"
#include "models/objects/PTModelAssetCharacter.h"
#include "models/objects/PTModelObjectAssetTrail.h"
#include "models/objects/PTModelObjectAssetFlag.h"
#include "models/objects/PTModelObjectButtonPurchase.h"

#define  LOG_TAG    "main"
#define  LOGD(...)  __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__)

using namespace cocos2d;

extern "C"
{

jint JNI_OnLoad(JavaVM *vm, void *reserved){
    JniHelper::setJavaVM(vm);
    return JNI_VERSION_1_4;
}

void Java_com_secrethq_utils_PTJniHelper_loadModelController(JNIEnv*  env, jobject thiz){
    PTLog("start laoding XML");

    PTModelController *mc = PTModelController::shared();
    while (!mc->loadDirectory("data"));

    PTLog("end loading XML");
}

jboolean Java_com_secrethq_utils_PTJniHelper_isAdNetworkActive(JNIEnv*  env, jobject thiz, jstring adNetworkNameString ){
const char* adNetworkName = env->GetStringUTFChars(adNetworkNameString, 0);
std::string platformName = "Google Play Store";

PTModelController *mc = PTModelController::shared();
PTPSettingsController* sc = PTPSettingsController::shared();

std::vector<PTModel*> screensArray  = mc->getModels("PTModelScreen");
if(screensArray.empty() || sc->removeAds()){
    return false;
}
for(int i=0; i < screensArray.size(); i++){
    PTModelScreen* model = (PTModelScreen*)screensArray.at( i );
    if(model->adNetworkFullscreen().compare( adNetworkName ) == 0){
        return true;
    }
    if(model->adNetworkBanner().compare( adNetworkName ) == 0){
        return true;    
    }
}

// check if this network in backup list
// banner
std::list<std::string> bannerList = PTModelGeneralSettings::shared()->adBannersList( platformName );
std::list<std::string>::const_iterator bannerIterator;
for (bannerIterator = bannerList.begin(); bannerIterator != bannerList.end(); ++bannerIterator) {
    if(strcmp((*bannerIterator).c_str(), adNetworkName) == 0){
        PTLog("ad Network (%s) in backup list (banner)", adNetworkName);
        return true;
    }
}

// interstitials
std::list<std::string> interstitialList = PTModelGeneralSettings::shared()->adInterstitialsList( platformName );
std::list<std::string>::const_iterator interstittialsIterator;
for (interstittialsIterator = interstitialList.begin(); interstittialsIterator != interstitialList.end(); ++interstittialsIterator) {
    if(strcmp((*interstittialsIterator).c_str(), adNetworkName) == 0){
        PTLog("ad Network (%s) in backup list (interstitials)", adNetworkName);
        return true;
    }
}

// check if network is used as reward video
std::vector<PTModel*> buttonsArray  = mc->getModels("PTModelObjectButtonPurchase");
if ( !buttonsArray.empty() ){
    for(int i=0; i < buttonsArray.size(); i++){
        PTModelObjectButtonPurchase* model = (PTModelObjectButtonPurchase*)buttonsArray.at( i );
        if ( model->isRewardedVideo()
             && model->rewardedVideoAdNetwork().compare( adNetworkName ) == 0 ) {
            return true;
        }
    }
}

// check if network is used as reward video
std::vector<PTModel*> charsArray  = mc->getModels("PTModelAssetCharacter");
if ( !charsArray.empty() ){
    for(int i=0; i < charsArray.size(); i++){
        PTModelAssetCharacter* model = (PTModelAssetCharacter*)charsArray.at( i );
        if ( model->purchaseMethod().compare("kRewardedVideos") == 0
             && model->rewardedVideoAdNetwork().compare( adNetworkName ) == 0 ) {
            return true;
        }
    }
}

return false;
}

void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv*  env, jobject thiz, jint w, jint h){
PTModelController *mc = PTModelController::shared();
if (!CCDirector::sharedDirector()->getOpenGLView()){
    CCEGLView *view = CCEGLView::sharedOpenGLView();
    view->setFrameSize(w, h);

    //loading general info 
    mc->clean();
    mc->loadFile( "data/PTModelGeneralSettings.0.attributes.xml", PTModelController::Attributes );
    mc->loadFile( "data/PTModelFont.0.attributes.xml", PTModelController::Attributes );     
    mc->loadFile( "data/PTModelScreen.0.attributes.xml", PTModelController::Attributes );
    mc->loadFile( "data/PTModelObjectLabel.0.attributes.xml", PTModelController::Attributes );
    mc->loadFile( "data/PTModelObjectLoadingBar.0.attributes.xml", PTModelController::Attributes );
    mc->loadFile( "data/PTModelScreen.0.connections.xml", PTModelController::Connections );

    PTPAppDelegate *pAppDelegate = new PTPAppDelegate();
    CCApplication::sharedApplication()->run();

    //clean up main model controller before starting loading Objects form XML files
    mc->clean();


}
else {
    PTLog("NATIVE RE INIT");
    ccGLInvalidateStateCache();        
    CCShaderCache::sharedShaderCache()->reloadDefaultShaders();
    ccDrawInit();
    CCTextureCache::reloadAllTextures();
    CCNotificationCenter::sharedNotificationCenter()->postNotification(EVNET_COME_TO_FOREGROUND, NULL);
    CCDirector::sharedDirector()->setGLDefaultValues(); 

}
}

}

所有#includes都是红色的!

您是否对解决此问题有任何想法?!

0 个答案:

没有答案