0

not duplicate of another question because the .gradle files was already configured as suggested.(Note, it's not that I can't build the project but the IDE fail to identify the importing)


Newbie to android development

I am using the latest android studio (v3.1.3)

I have download source from a site and try to run that on an android device, which is successful, ie, I could build the apk but in android studio IDE, the import class shows error, the class seems imported from an aar file.

How to make the importing work(not showing error) in IDE?

enter image description here

And here is the build.gradle in app:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    buildToolsVersion "27.0.0"
    defaultConfig {
        applicationId "com.tencent.tmgp.yybtestsdk"
        minSdkVersion 14
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile(name: 'YSDK_Android_1.3.9_917', ext: 'aar')
}

here is the build.gradle in project

   // Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.3'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        flatDir {
            dirs 'libs'
        }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
armnotstrong
  • 8,605
  • 16
  • 65
  • 130
  • have you included in your project file in gradle also ? – Umair Aug 01 '18 at 14:30
  • Possible duplicate of [How to manually include external aar package using new Gradle Android Build System](https://stackoverflow.com/questions/16682847/how-to-manually-include-external-aar-package-using-new-gradle-android-build-syst) – Christopher Aug 01 '18 at 14:35
  • @Christopher sine the `.gradle` file was already configured as suggested, I think it's not a duplicate question, check edit :D – armnotstrong Aug 01 '18 at 14:59
  • Ok, I think you're right. So it's compiling, but the Android Studio just shows this errors? Try to perform the usual cleanup stuff: restart, invalidate caches, close AS, remove .idea folder, restart AS and reimport your project. With 3.1.x AS is getting quite unreliable. – Christopher Aug 01 '18 at 15:02
  • @Christopher not again~ T_T just do that days ago, but worth a try, thanks – armnotstrong Aug 01 '18 at 15:05

1 Answers1

1

Update your gradle.build (in the PROJECT level, not app level) like so.

        flatDir {
            dirs 'libs'
            dirs 'libs/app'
            dirs "../app/libs"
        }

Try changing

compile(name: 'YSDK_Android_1.3.9_917', ext: 'aar')

to

implementation(name: 'YSDK_Android_1.3.9_917', ext: 'aar')
letsCode
  • 2,774
  • 1
  • 13
  • 37