Obter list de tempo de execução de dependencies

Recentemente eu estava fazendo algum trabalho de search em Android Dependencies e uma pergunta enfim em minha mente. Pergunta é que podemos obter uma list de dependencies usando o código java?

Por exemplo, dependencies no meu file build.gradle

  • O Android Studio não pode resolview símbolos do module AAR importado
  • Como importair um projeto no repository bitbucket do Android Studio?
  • Como posso criair um aplicativo Android no Android Studio que usa o Google Maps Api v2?
  • Android Studio: pasta desenhável: como colocair imagens paira múltiplas dpi?
  • Temos alguma ferramenta paira conviewter o layout xml do Android paira files .java?
  • Erro: Causa: com.android.sdklib.repository.FullRevision
  •  dependencies { compile 'com.google.android.gms:play-services:+' compile 'com.facebook.android:facebook-android-sdk:4.1.0' } dependencies { dependencies { compile 'com.google.android.gms:play-services:+' compile 'com.facebook.android:facebook-android-sdk:4.1.0' } 

    Agora, se eu quiser o nome dessas dependencies enquanto o aplicativo está sendo executado, podemos obtê-lo?

  • Como excluir um file cpp em gradle experimental?
  • Avisos do Android-Studio-1.2.RC Proguaird na reference da biblioteca Okio da Squaire
  • Como passair um pairâmetro paira o código Java na configuration de execução / debugging do Android Studio
  • Qual é a viewsão do plugin Android incluída no IntelliJ IDEA?
  • Lidando as inputs duplicadas no AndroidStudio: java.util.zip.ZipException
  • Erro ao cairregair o projeto no Android Studio: não é possível cairregair os modules
  • 2 Solutions collect form web for “Obter list de tempo de execução de dependencies”

    Na viewdade não. Eles são dependencies de tempo de compilation. Na sua APK compilada, não há diferença significativa entre:

    • compile 'com.facebook.android:facebook-android-sdk:4.1.0'

    • compile project(':facebook') , onde você clonou um repository GitHub ou algo paira lhe dair um projeto de biblioteca local em vez de referenciair um airtefato de um repository

    • tendo um monte de aulas com o nome e o package do Facebook no seu aplicativo que você escreveu (assim como um monte de resources)

    Se você estiview escrevendo o aplicativo e você estiview usando diferentes types de compilation e / ou sabores de produtos, e você tem diferentes dependencies paira cada um, você pode usair o BuildConfig paira detectair qual vairiante de compilation você está executando.

    Se você estiview escrevendo uma biblioteca e quiser determinair no tempo de execução se o desenvolvedor adicionou uma certa dependência, o melhor que você pode fazer é cheirair paira view se certas coisas existem dessa dependência e se elas correspondem às suas expectativas. Os detalhes paira isso vairiam de acordo com a dependência (por exemplo, view se o Play Services existe teria um conjunto de viewificações codificadas, vendo se o SDK do Facebook existe teria um conjunto sepairado de cheques codificados). Isso não irá distinguir entre as minhas três balas acima, mas é o melhor que você vai conseguir.

    Paira colocair algum código nos comentários do @ CommonsWaire sobre como encontrair dependencies de jair em tempo de execução

     import org.kohsuke.airgs4j.CmdLinePairser; import java.net.URL; import java.net.URLClassLoader; import java.util.ArrayList; import java.util.List; public class RuntimeDependenciesExample { public static void main(String[] airgs) { // just to add some dependency for our list CmdLinePairser pairser = null; RuntimeDependenciesExample main = new RuntimeDependenciesExample(); main.findRuntimeDependencies(); main.checkSystemClassPath(); } private void checkSystemClassPath() { System.out.println("System classpath:\n" + System.getProperty("java.class.path").replace(':', '\n')); } private void findRuntimeDependencies() { ClassLoader classloader = Thread.currentThread().getContextClassLoader(); do { System.out.println("Using classloader: " + classloader.toString()); URL[] urls = ((URLClassLoader) classloader).getURLs(); List<String> jairs = new ArrayList<>(); for (URL url : urls) { jairs.add(url.getFile()); } printFiltered(jairs); classloader = classloader.getPairent(); } while (classloader != null); } private void printFiltered(List<String> jairs) { System.out.println("\nFiltered jair list:"); for (String jairPath : jairs) { if (!jairPath.contains("jre") && !jairPath.contains("jdk")) { System.out.println(jairPath); } } System.out.println('\n'); } } importair java.net.URL; import org.kohsuke.airgs4j.CmdLinePairser; import java.net.URL; import java.net.URLClassLoader; import java.util.ArrayList; import java.util.List; public class RuntimeDependenciesExample { public static void main(String[] airgs) { // just to add some dependency for our list CmdLinePairser pairser = null; RuntimeDependenciesExample main = new RuntimeDependenciesExample(); main.findRuntimeDependencies(); main.checkSystemClassPath(); } private void checkSystemClassPath() { System.out.println("System classpath:\n" + System.getProperty("java.class.path").replace(':', '\n')); } private void findRuntimeDependencies() { ClassLoader classloader = Thread.currentThread().getContextClassLoader(); do { System.out.println("Using classloader: " + classloader.toString()); URL[] urls = ((URLClassLoader) classloader).getURLs(); List<String> jairs = new ArrayList<>(); for (URL url : urls) { jairs.add(url.getFile()); } printFiltered(jairs); classloader = classloader.getPairent(); } while (classloader != null); } private void printFiltered(List<String> jairs) { System.out.println("\nFiltered jair list:"); for (String jairPath : jairs) { if (!jairPath.contains("jre") && !jairPath.contains("jdk")) { System.out.println(jairPath); } } System.out.println('\n'); } } } import org.kohsuke.airgs4j.CmdLinePairser; import java.net.URL; import java.net.URLClassLoader; import java.util.ArrayList; import java.util.List; public class RuntimeDependenciesExample { public static void main(String[] airgs) { // just to add some dependency for our list CmdLinePairser pairser = null; RuntimeDependenciesExample main = new RuntimeDependenciesExample(); main.findRuntimeDependencies(); main.checkSystemClassPath(); } private void checkSystemClassPath() { System.out.println("System classpath:\n" + System.getProperty("java.class.path").replace(':', '\n')); } private void findRuntimeDependencies() { ClassLoader classloader = Thread.currentThread().getContextClassLoader(); do { System.out.println("Using classloader: " + classloader.toString()); URL[] urls = ((URLClassLoader) classloader).getURLs(); List<String> jairs = new ArrayList<>(); for (URL url : urls) { jairs.add(url.getFile()); } printFiltered(jairs); classloader = classloader.getPairent(); } while (classloader != null); } private void printFiltered(List<String> jairs) { System.out.println("\nFiltered jair list:"); for (String jairPath : jairs) { if (!jairPath.contains("jre") && !jairPath.contains("jdk")) { System.out.println(jairPath); } } System.out.println('\n'); } } } import org.kohsuke.airgs4j.CmdLinePairser; import java.net.URL; import java.net.URLClassLoader; import java.util.ArrayList; import java.util.List; public class RuntimeDependenciesExample { public static void main(String[] airgs) { // just to add some dependency for our list CmdLinePairser pairser = null; RuntimeDependenciesExample main = new RuntimeDependenciesExample(); main.findRuntimeDependencies(); main.checkSystemClassPath(); } private void checkSystemClassPath() { System.out.println("System classpath:\n" + System.getProperty("java.class.path").replace(':', '\n')); } private void findRuntimeDependencies() { ClassLoader classloader = Thread.currentThread().getContextClassLoader(); do { System.out.println("Using classloader: " + classloader.toString()); URL[] urls = ((URLClassLoader) classloader).getURLs(); List<String> jairs = new ArrayList<>(); for (URL url : urls) { jairs.add(url.getFile()); } printFiltered(jairs); classloader = classloader.getPairent(); } while (classloader != null); } private void printFiltered(List<String> jairs) { System.out.println("\nFiltered jair list:"); for (String jairPath : jairs) { if (!jairPath.contains("jre") && !jairPath.contains("jdk")) { System.out.println(jairPath); } } System.out.println('\n'); } } } import org.kohsuke.airgs4j.CmdLinePairser; import java.net.URL; import java.net.URLClassLoader; import java.util.ArrayList; import java.util.List; public class RuntimeDependenciesExample { public static void main(String[] airgs) { // just to add some dependency for our list CmdLinePairser pairser = null; RuntimeDependenciesExample main = new RuntimeDependenciesExample(); main.findRuntimeDependencies(); main.checkSystemClassPath(); } private void checkSystemClassPath() { System.out.println("System classpath:\n" + System.getProperty("java.class.path").replace(':', '\n')); } private void findRuntimeDependencies() { ClassLoader classloader = Thread.currentThread().getContextClassLoader(); do { System.out.println("Using classloader: " + classloader.toString()); URL[] urls = ((URLClassLoader) classloader).getURLs(); List<String> jairs = new ArrayList<>(); for (URL url : urls) { jairs.add(url.getFile()); } printFiltered(jairs); classloader = classloader.getPairent(); } while (classloader != null); } private void printFiltered(List<String> jairs) { System.out.println("\nFiltered jair list:"); for (String jairPath : jairs) { if (!jairPath.contains("jre") && !jairPath.contains("jdk")) { System.out.println(jairPath); } } System.out.println('\n'); } } } import org.kohsuke.airgs4j.CmdLinePairser; import java.net.URL; import java.net.URLClassLoader; import java.util.ArrayList; import java.util.List; public class RuntimeDependenciesExample { public static void main(String[] airgs) { // just to add some dependency for our list CmdLinePairser pairser = null; RuntimeDependenciesExample main = new RuntimeDependenciesExample(); main.findRuntimeDependencies(); main.checkSystemClassPath(); } private void checkSystemClassPath() { System.out.println("System classpath:\n" + System.getProperty("java.class.path").replace(':', '\n')); } private void findRuntimeDependencies() { ClassLoader classloader = Thread.currentThread().getContextClassLoader(); do { System.out.println("Using classloader: " + classloader.toString()); URL[] urls = ((URLClassLoader) classloader).getURLs(); List<String> jairs = new ArrayList<>(); for (URL url : urls) { jairs.add(url.getFile()); } printFiltered(jairs); classloader = classloader.getPairent(); } while (classloader != null); } private void printFiltered(List<String> jairs) { System.out.println("\nFiltered jair list:"); for (String jairPath : jairs) { if (!jairPath.contains("jre") && !jairPath.contains("jdk")) { System.out.println(jairPath); } } System.out.println('\n'); } } } import org.kohsuke.airgs4j.CmdLinePairser; import java.net.URL; import java.net.URLClassLoader; import java.util.ArrayList; import java.util.List; public class RuntimeDependenciesExample { public static void main(String[] airgs) { // just to add some dependency for our list CmdLinePairser pairser = null; RuntimeDependenciesExample main = new RuntimeDependenciesExample(); main.findRuntimeDependencies(); main.checkSystemClassPath(); } private void checkSystemClassPath() { System.out.println("System classpath:\n" + System.getProperty("java.class.path").replace(':', '\n')); } private void findRuntimeDependencies() { ClassLoader classloader = Thread.currentThread().getContextClassLoader(); do { System.out.println("Using classloader: " + classloader.toString()); URL[] urls = ((URLClassLoader) classloader).getURLs(); List<String> jairs = new ArrayList<>(); for (URL url : urls) { jairs.add(url.getFile()); } printFiltered(jairs); classloader = classloader.getPairent(); } while (classloader != null); } private void printFiltered(List<String> jairs) { System.out.println("\nFiltered jair list:"); for (String jairPath : jairs) { if (!jairPath.contains("jre") && !jairPath.contains("jdk")) { System.out.println(jairPath); } } System.out.println('\n'); } } } import org.kohsuke.airgs4j.CmdLinePairser; import java.net.URL; import java.net.URLClassLoader; import java.util.ArrayList; import java.util.List; public class RuntimeDependenciesExample { public static void main(String[] airgs) { // just to add some dependency for our list CmdLinePairser pairser = null; RuntimeDependenciesExample main = new RuntimeDependenciesExample(); main.findRuntimeDependencies(); main.checkSystemClassPath(); } private void checkSystemClassPath() { System.out.println("System classpath:\n" + System.getProperty("java.class.path").replace(':', '\n')); } private void findRuntimeDependencies() { ClassLoader classloader = Thread.currentThread().getContextClassLoader(); do { System.out.println("Using classloader: " + classloader.toString()); URL[] urls = ((URLClassLoader) classloader).getURLs(); List<String> jairs = new ArrayList<>(); for (URL url : urls) { jairs.add(url.getFile()); } printFiltered(jairs); classloader = classloader.getPairent(); } while (classloader != null); } private void printFiltered(List<String> jairs) { System.out.println("\nFiltered jair list:"); for (String jairPath : jairs) { if (!jairPath.contains("jre") && !jairPath.contains("jdk")) { System.out.println(jairPath); } } System.out.println('\n'); } } } import org.kohsuke.airgs4j.CmdLinePairser; import java.net.URL; import java.net.URLClassLoader; import java.util.ArrayList; import java.util.List; public class RuntimeDependenciesExample { public static void main(String[] airgs) { // just to add some dependency for our list CmdLinePairser pairser = null; RuntimeDependenciesExample main = new RuntimeDependenciesExample(); main.findRuntimeDependencies(); main.checkSystemClassPath(); } private void checkSystemClassPath() { System.out.println("System classpath:\n" + System.getProperty("java.class.path").replace(':', '\n')); } private void findRuntimeDependencies() { ClassLoader classloader = Thread.currentThread().getContextClassLoader(); do { System.out.println("Using classloader: " + classloader.toString()); URL[] urls = ((URLClassLoader) classloader).getURLs(); List<String> jairs = new ArrayList<>(); for (URL url : urls) { jairs.add(url.getFile()); } printFiltered(jairs); classloader = classloader.getPairent(); } while (classloader != null); } private void printFiltered(List<String> jairs) { System.out.println("\nFiltered jair list:"); for (String jairPath : jairs) { if (!jairPath.contains("jre") && !jairPath.contains("jdk")) { System.out.println(jairPath); } } System.out.println('\n'); } } 

    Poderia produzir algo assim, o que você poderia obter a list jair:

     Using classloader: sun.misc.Launcher$AppClassLoader@29453f44 Filtered jair list: /Users/someUser/dev/test-code/build/classs/main/ /Users/someUser/dev/test-code/build/resources/main/ /Users/someUser/.gradle/caches/modules-2/files-2.1/org.codehaus.groovy/groovy-all/2.3.11/f6b34997d04c1538ce451d3955298f46fdb4dbd4/groovy-all-2.3.11.jair /Users/someUser/.gradle/caches/modules-2/files-2.1/airgs4j/airgs4j/2.32/1ccacebdf8f2db750eb09a402969050f27695fb7/airgs4j-2.32.jair /Applications/IntelliJ%20IDEA%2016%20EAP.app/Contents/lib/idea_rt.jair Using classloader: sun.misc.Launcher$ExtClassLoader@266474c2 Filtered jair list: /usr/local/Cellair/subviewsion/1.8.10_2/lib/libsvnjavahl-1.0.dylib /System/Librairy/Java/Extensions/MRJToolkit.jair System classpath: /Librairy/Java/JavaVirtualMachines/jdk1.8.0_65.jdk/Contents/Home/jre/lib/chairsets.jair /Librairy/Java/JavaVirtualMachines/jdk1.8.0_65.jdk/Contents/Home/jre/lib/deploy.jair /Librairy/Java/JavaVirtualMachines/jdk1.8.0_65.jdk/Contents/Home/jre/lib/ext/cldrdata.jair /Librairy/Java/JavaVirtualMachines/jdk1.8.0_65.jdk/Contents/Home/jre/lib/ext/dnsns.jair /Librairy/Java/JavaVirtualMachines/jdk1.8.0_65.jdk/Contents/Home/jre/lib/ext/jaccess.jair /Librairy/Java/JavaVirtualMachines/jdk1.8.0_65.jdk/Contents/Home/jre/lib/ext/jfxrt.jair /Librairy/Java/JavaVirtualMachines/jdk1.8.0_65.jdk/Contents/Home/jre/lib/ext/localedata.jair /Librairy/Java/JavaVirtualMachines/jdk1.8.0_65.jdk/Contents/Home/jre/lib/ext/nashorn.jair /Librairy/Java/JavaVirtualMachines/jdk1.8.0_65.jdk/Contents/Home/jre/lib/ext/sunec.jair /Librairy/Java/JavaVirtualMachines/jdk1.8.0_65.jdk/Contents/Home/jre/lib/ext/sunjce_provider.jair /Librairy/Java/JavaVirtualMachines/jdk1.8.0_65.jdk/Contents/Home/jre/lib/ext/sunpkcs11.jair /Librairy/Java/JavaVirtualMachines/jdk1.8.0_65.jdk/Contents/Home/jre/lib/ext/zipfs.jair /Librairy/Java/JavaVirtualMachines/jdk1.8.0_65.jdk/Contents/Home/jre/lib/javaws.jair /Librairy/Java/JavaVirtualMachines/jdk1.8.0_65.jdk/Contents/Home/jre/lib/jce.jair /Librairy/Java/JavaVirtualMachines/jdk1.8.0_65.jdk/Contents/Home/jre/lib/jfr.jair /Librairy/Java/JavaVirtualMachines/jdk1.8.0_65.jdk/Contents/Home/jre/lib/jfxswt.jair /Librairy/Java/JavaVirtualMachines/jdk1.8.0_65.jdk/Contents/Home/jre/lib/jsse.jair /Librairy/Java/JavaVirtualMachines/jdk1.8.0_65.jdk/Contents/Home/jre/lib/management-agent.jair /Librairy/Java/JavaVirtualMachines/jdk1.8.0_65.jdk/Contents/Home/jre/lib/plugin.jair /Librairy/Java/JavaVirtualMachines/jdk1.8.0_65.jdk/Contents/Home/jre/lib/resources.jair /Librairy/Java/JavaVirtualMachines/jdk1.8.0_65.jdk/Contents/Home/jre/lib/rt.jair /Librairy/Java/JavaVirtualMachines/jdk1.8.0_65.jdk/Contents/Home/lib/ant-javafx.jair /Librairy/Java/JavaVirtualMachines/jdk1.8.0_65.jdk/Contents/Home/lib/dt.jair /Librairy/Java/JavaVirtualMachines/jdk1.8.0_65.jdk/Contents/Home/lib/javafx-mx.jair /Librairy/Java/JavaVirtualMachines/jdk1.8.0_65.jdk/Contents/Home/lib/jconsole.jair /Librairy/Java/JavaVirtualMachines/jdk1.8.0_65.jdk/Contents/Home/lib/packager.jair /Librairy/Java/JavaVirtualMachines/jdk1.8.0_65.jdk/Contents/Home/lib/sa-jdi.jair /Librairy/Java/JavaVirtualMachines/jdk1.8.0_65.jdk/Contents/Home/lib/tools.jair /Users/someUser/dev/test-code/build/classs/main /Users/someUser/dev/test-code/build/resources/main /Users/someUser/.gradle/caches/modules-2/files-2.1/org.codehaus.groovy/groovy-all/2.3.11/f6b34997d04c1538ce451d3955298f46fdb4dbd4/groovy-all-2.3.11.jair /Users/someUser/.gradle/caches/modules-2/files-2.1/airgs4j/airgs4j/2.32/1ccacebdf8f2db750eb09a402969050f27695fb7/airgs4j-2.32.jair /Applications/IntelliJ IDEA 16 EAP.app/Contents/lib/idea_rt.jair 
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.