Android Studio compiler doesn't compile my AdsClass

Voloda2 :

I created a new class. It is AdsClass.java. I added no existence class to check if compiler see my class.

Android studio must tell me about compiler error like NoExistanceClass not found. But Android Studio tells that everything okay and it installed my app on Android device.

How can I force the compiler to compile AdsClass?

package org.cocos2dx.cpp;

public class AdsClass {

 public void showInterstitial() {
    NoExistanceClass my;
 }
}

My AdsClass.java path is

My AdsClass.java path is

Settings.gradle

include ':libcocos2dx'
project(':libcocos2dx').projectDir = new File(settingsDir,      '../cocos2d/cocos/platform/android/libcocos2dx')
include ':mahjongDroid'
project(':mahjongDroid').projectDir = new File(settingsDir, 'app')

my left pane

enter image description here

Pavneet_Singh :

You are creating org.cocos2dx.cpp package outside main/java and by default Gradle default java source directory is src/main/java so you can add your package to build path or there are few solutions as:

  1. Add your new java package source to build path in app/build.gradle(app) using

    android {
        compileSdkVersion 29
        buildToolsVersion "29.0.2"
    
        defaultConfig {
           // ...
        }
    
        sourceSets { // add package to path
            main.java.srcDirs += 'src/org/cocos2dx/cpp'
        }
    
    }
    
  2. Or, you can move org.cocos2dx.cpp package/files inside src/main/java package

  3. You can create a library module under your repo.


Example:

sourceSets { // add package to path
    main.java.srcDirs += 'src/org'
}

enter image description here

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=174638&siteId=1