Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio: How to see sources for android support v4 and v7?

In Android Studio support library appcompat (for ActionBar) is defined as Gradle dependency.

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:21.0.3'
}

That resolves to get v4 as well.

How to see source when clicking to into classes?

e.g. android.support.v4.widget.DrawerLayout

Currently Android Studio says

// IntelliJ API Decompiler stub source generated from a class file
// Implementation of methods is not available

For ADT it was How to add source + javadoc for android-support-v7?

like image 892
Paul Verest Avatar asked Dec 22 '14 09:12

Paul Verest


People also ask

What is v4 and v7 in Android?

v4 has largest set of API's than others like App component, User Interface Feature, data handling ,network connectivity and utilities. v7 provided specfic feature sets that can be included in your app independently.

How do I add a library Android support v7 Appcompat in Android Studio?

In the Properties window, select the "Android" properties group at left and locate the Library properties at right. Select /path/to/appcompat/ and Click Remove. Click Add to open the Project Selection dialog. From the list of available library projects, select v7 appcompat library and click OK.

Where is the source code in Android Studio?

From within Android Studio, navigate to Tools -> Android -> SDK Manager. Once open, you'll need to download the Sources for Android SDK as shown below. Once you have the sources downloaded, you can find the source code inside of the "sources" folder of your SDK (wherever that may be on your computer).


2 Answers

Following from the above research done by Paul Verest...

IDE: Android studio 1.3.2

It is a 2-step process: Consider this sample build.gradle

1) Add the following to your build.gradle (Module:app) - search the 2 //Add comments below.

apply plugin: 'com.android.application'
apply plugin: 'idea' //Add

android {
  compileSdkVersion 21
  buildToolsVersion "21.1.2"

  defaultConfig {
      applicationId "com.mycompany.android.myapp"
      minSdkVersion 16
      targetSdkVersion 21
      versionCode 1
      versionName "1.0"
  }
  buildTypes {
      release {
          proguardFiles getDefaultProguardFile('proguard-android.txt'),   'proguard-rules.pro'
      }
  }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.1.0'
}

//Add
idea {
      module {
          downloadJavadoc = true
          downloadSources = true
      }
  }

2) Rebuild project.

After this point if you want to see source in Android Studio, it will pull up the source *.java instead of decompiled *.class

like image 183
dessertcook Avatar answered Oct 14 '22 18:10

dessertcook


Thanks to Setu for hint. As I already had all sources before, I just added in app/build.gradle

apply plugin: 'idea'
idea {
    module{
        sourceDirs += file("E:\\Android\\sdk\\extras\\android\\support\\v4\\src\\")
        sourceDirs += file("E:\\Android\\sources\\platform_frameworks_support\\v7\\appcompat\\src")
    }
}

below dependencies section and press "Sync project with Gradle Files"

like image 35
Paul Verest Avatar answered Oct 14 '22 19:10

Paul Verest