Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not getting all dependencies #18

Open
eyJhb opened this issue Jul 31, 2020 · 1 comment
Open

Not getting all dependencies #18

eyJhb opened this issue Jul 31, 2020 · 1 comment

Comments

@eyJhb
Copy link
Contributor

eyJhb commented Jul 31, 2020

There are currently a problem, where it will not get all the dependencies + it will not place them in the correct deps (plugin, buildscript, etc.)

I have been trying with AntennaPod ( https://github.com/AntennaPod/AntennaPod ), where it will

  1. Constantly set the Gradle version in the gradle-env.json to something like 4.x.x, even if a higher version is specified with -g
  2. Not have the right deps the right places, hence I have done something like this
  mkInitScript = projectSpec:
    let
      repos = mapAttrs (mkRepo projectSpec.name) projectSpec.dependencies;
      test = mkRepo "test" "test" (projectSpec.dependencies.buildscript ++ projectSpec.dependencies.project ++ projectSpec.dependencies.plugin);
    in
      writeText "init.gradle" ''
        static def offlineRepo(RepositoryHandler repositories, String env, String path) {
            repositories.clear()
            repositories.maven {
                name "Nix''${env.capitalize()}MavenOffline"
                url path
                metadataSources {
                    it.gradleMetadata()
                    it.mavenPom()
                    it.artifact()
                }
            }
            repositories.ivy {
                name "Nix''${env.capitalize()}IvyOffline"
                url path
                layout "maven"
                metadataSources {
                    it.gradleMetadata()
                    it.ivyDescriptor()
                    it.artifact()
                }
            }
        }

        gradle.settingsEvaluated {
            offlineRepo(it.pluginManagement.repositories, "plugin", "${test}")
        }

        gradle.projectsLoaded {
            allprojects {
                buildscript {
                    offlineRepo(repositories, "buildscript", "${test}")
                }
                offlineRepo(repositories, "project", "${test}")
            }
        }
      '';

To work around it. Is there even a reason to separate them?

  1. Not fetch all the required dependencies

You can try it for yourself with this patch applied to gradle-env.nix

  mkInitScript = projectSpec:
    let
      repos = mapAttrs (mkRepo projectSpec.name) projectSpec.dependencies;
      test = mkRepo "test" "test" (projectSpec.dependencies.buildscript ++ projectSpec.dependencies.project ++ projectSpec.dependencies.plugin);
    in
      writeText "init.gradle" ''
        static def offlineRepo(RepositoryHandler repositories, String env, String path) {
            repositories.clear()
            repositories.maven {
                name "Nix''${env.capitalize()}MavenOffline"
                url path
                metadataSources {
                    it.gradleMetadata()
                    it.mavenPom()
                    it.artifact()
                }
            }
            repositories.ivy {
                name "Nix''${env.capitalize()}IvyOffline"
                url path
                layout "maven"
                metadataSources {
                    it.gradleMetadata()
                    it.ivyDescriptor()
                    it.artifact()
                }
            }
        }

        gradle.settingsEvaluated {
            offlineRepo(it.pluginManagement.repositories, "plugin", "${test}")
        }

        gradle.projectsLoaded {
            allprojects {
                buildscript {
                    offlineRepo(repositories, "buildscript", "${test}")
                }
                offlineRepo(repositories, "project", "${test}")
            }
        }
      '';

And using this default.nix

{ pkgs ? import <nixpkgs> {config.android_sdk.accept_license = true;} }:

with pkgs;

let
  buildGradle = pkgs.callPackage ./../gradle2nix/app/src/dist/share/gradle-env.nix {};

  sdk = pkgs.androidenv.composeAndroidPackages {
    buildToolsVersions = [ "28.0.3" ];
    # buildToolsVersions = [ "28.0.3" ];
    platformVersions = [ "28" ];
    abiVersions = [ "x86" "x86_64"];
    # toolsVersion = "26.1.1";
  };

  gradle2nix = buildGradle {
    envSpec = ./gradle-env.json;

    src = pkgs.fetchFromGitHub {
      owner = "AntennaPod";
      repo = "AntennaPod";
      rev = "1.8.3";
      sha256 = "0qhp50jz7nf2rf4v8p2y2z1p8js6h6313cm5b829bxz3h12ib8ai";
    };

    # gradleFlags = [ "assemble" ];
    gradleFlags = [ "clean" "assemblePlayDebug" "assemblePlayRelease" ];

    preBuild = ''
      echo "sdk.dir = ${sdk.androidsdk}/libexec/android-sdk" > local.properties
      printf "\nandroid.aapt2FromMavenOverride=${sdk.androidsdk}/libexec/android-sdk/build-tools/29.0.3/aapt2" >> gradle.properties
    '';

    installPhase = ''
      mkdir -p $out
      ls -alR app/build
      find . -name '*.apk' -exec cp {} $out \;
    '';
  };

in gradle2nix

The getting dependencies should work, else try what I did in #17 , and delete the cache.

@eyJhb
Copy link
Contributor Author

eyJhb commented Aug 1, 2020

I think that #17 needs to be fixed, and then this might go away.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant