5
5
import 'dart:io' ;
6
6
import 'package:path/path.dart' ;
7
7
8
+ import 'package:jnigen/src/logging/logging.dart' ;
9
+
8
10
class AndroidSdkTools {
9
11
/// get path for android API sources
10
12
static Future <String ?> _getVersionDir (
@@ -25,7 +27,9 @@ class AndroidSdkTools {
25
27
26
28
static Future <String ?> getAndroidSourcesPath (
27
29
{String ? sdkRoot, required List <int > versionOrder}) async {
28
- return _getVersionDir ('sources' , sdkRoot, versionOrder);
30
+ final dir = _getVersionDir ('sources' , sdkRoot, versionOrder);
31
+ log.info ('Found sources at $dir ' );
32
+ return dir;
29
33
}
30
34
31
35
static Future <String ?> _getFile (String relative, String file, String ? sdkRoot,
@@ -34,6 +38,7 @@ class AndroidSdkTools {
34
38
if (platform == null ) return null ;
35
39
final filePath = join (platform, file);
36
40
if (await File (filePath).exists ()) {
41
+ log.info ('Found $filePath ' );
37
42
return filePath;
38
43
}
39
44
return null ;
@@ -68,28 +73,31 @@ task listDependencies(type: Copy) {
68
73
/// If current project is not directly buildable by gradle, eg: a plugin,
69
74
/// a relative path to other project can be specified using [androidProject] .
70
75
static List <String > getGradleClasspaths ([String androidProject = '.' ]) {
71
- stderr. writeln ('trying to obtain gradle classpaths...' );
76
+ log. info ('trying to obtain gradle classpaths...' );
72
77
final android = join (androidProject, 'android' );
73
78
final buildGradle = join (android, 'build.gradle' );
74
79
final buildGradleOld = join (android, 'build.gradle.old' );
75
80
final origBuild = File (buildGradle);
76
81
final script = origBuild.readAsStringSync ();
77
82
origBuild.renameSync (buildGradleOld);
78
83
origBuild.createSync ();
84
+ log.finer ('Writing temporary gradle script with stub function...' );
79
85
origBuild.writeAsStringSync ('$script \n $_gradleListDepsFunction \n ' );
86
+ log.finer ('Running gradle wrapper...' );
80
87
final procRes = Process .runSync ('./gradlew' , ['-q' , 'listDependencies' ],
81
88
workingDirectory: android);
89
+ log.finer ('Restoring build scripts' );
82
90
origBuild.writeAsStringSync (script);
83
91
File (buildGradleOld).deleteSync ();
84
92
if (procRes.exitCode != 0 ) {
93
+ final inAndroidProject =
94
+ (androidProject == '.' ) ? '' : ' in $androidProject ' ;
85
95
throw Exception ('\n\n gradle exited with exit code ${procRes .exitCode }\n '
86
96
'This can be related to a known issue with gradle. Please run '
87
- '`flutter build apk` in $androidProject and try again\n ' );
88
- }
89
- final gradleClassPaths = (procRes.stdout as String ).split ('\n ' );
90
- if (gradleClassPaths.last.isEmpty) {
91
- gradleClassPaths.removeLast ();
97
+ '`flutter build apk`$inAndroidProject and try again\n ' );
92
98
}
93
- return gradleClassPaths;
99
+ final classpaths = (procRes.stdout as String ).trim ().split ('\n ' );
100
+ log.info ('Found release build classpath with ${classpaths .length } entries' );
101
+ return classpaths;
94
102
}
95
103
}
0 commit comments