Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
d2dbd2b
WIP: add gRPC tests
simonrozsival Jun 8, 2022
ea8b368
Merge branch 'main' of https://github.com/dotnet/runtime into android…
simonrozsival Jun 9, 2022
1dcf0e8
Fix AOT and trimming
simonrozsival Jun 9, 2022
2941f15
WIP
simonrozsival Jun 23, 2022
66b2939
Implement IncludeNetworkSecurityConfig
simonrozsival Jun 27, 2022
6ef8d85
Use IncludeNetworkSecurityConfig
simonrozsival Jun 27, 2022
5740a9b
Fix gRPC test
simonrozsival Jun 27, 2022
b99fc44
Avoid git checkout
simonrozsival Jun 27, 2022
be51a78
Remove unnecessary code
simonrozsival Jun 27, 2022
0d4837c
Merge branch 'main' of https://github.com/dotnet/runtime into android…
simonrozsival Jul 20, 2022
28629ae
WIP: start working on CI configuration
simonrozsival Jul 20, 2022
85eb854
Remove WinHttpHandler
simonrozsival Jul 29, 2022
b4b2d09
Fix problem with SSL
simonrozsival Jul 29, 2022
9dac1c4
Change server host
simonrozsival Jul 29, 2022
3a8908f
Setup CI (#1)
directhex Jul 29, 2022
3276d50
Use tls
simonrozsival Jul 29, 2022
b7b40e7
Update yml
simonrozsival Jul 29, 2022
44bd21c
Revert changes to the mono Android sample app
simonrozsival Jul 29, 2022
805790e
Merge branch 'main' of github.com:dotnet/runtime into simonrozsival/a…
simonrozsival Aug 9, 2022
6e7f96e
Bump android image version
simonrozsival Aug 9, 2022
41d80a2
Bump image version
simonrozsival Aug 10, 2022
124ed66
Enable TLS
simonrozsival Aug 10, 2022
39f4009
Remove hardcoded package versions
simonrozsival Aug 12, 2022
a11e4a8
Update package versions
simonrozsival Aug 12, 2022
764f745
Update package versions
simonrozsival Aug 12, 2022
e996d02
Rename pipeline
simonrozsival Aug 24, 2022
09c67c3
Move interop tests website dependencies versions to Versions.props
simonrozsival Aug 24, 2022
c1bb0dd
Add cred scan supression for the interop test server private key
simonrozsival Aug 24, 2022
b9a02d8
Fix licenses
simonrozsival Aug 24, 2022
6691bc0
Remove dependencies
simonrozsival Aug 24, 2022
0722991
Merge branch 'main' into simonrozsival/android-grpc-client-tests
simonrozsival Aug 24, 2022
32034ad
Fix path to Versions.props
simonrozsival Aug 24, 2022
785ba5e
Merge branch 'simonrozsival/android-grpc-client-tests' of github.com:…
simonrozsival Aug 24, 2022
d2ac3d8
Remove unnecessary dependency version
simonrozsival Aug 24, 2022
3bb36bf
Fix building docker image
simonrozsival Aug 24, 2022
2cf9df9
Change pfx password
simonrozsival Aug 24, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Implement IncludeNetworkSecurityConfig
  • Loading branch information
simonrozsival committed Jun 27, 2022
commit 66b29397c43ef48837a2a6d05beb509b287d4c59
3 changes: 3 additions & 0 deletions src/tasks/AndroidAppBuilder/AndroidAppBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ public class AndroidAppBuilderTask : Task
/// </summary>
public string? NativeMainSource { get; set; }

public bool IncludeNetworkSecurityConfig { get; set; }

public string? KeyStorePath { get; set; }

public bool ForceInterpreter { get; set; }
Expand All @@ -105,6 +107,7 @@ public override bool Execute()
apkBuilder.BuildToolsVersion = BuildToolsVersion;
apkBuilder.StripDebugSymbols = StripDebugSymbols;
apkBuilder.NativeMainSource = NativeMainSource;
apkBuilder.IncludeNetworkSecurityConfig = IncludeNetworkSecurityConfig;
apkBuilder.KeyStorePath = KeyStorePath;
apkBuilder.ForceInterpreter = ForceInterpreter;
apkBuilder.ForceAOT = ForceAOT;
Expand Down
29 changes: 28 additions & 1 deletion src/tasks/AndroidAppBuilder/ApkBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class ApkBuilder
public string OutputDir { get; set; } = ""!;
public bool StripDebugSymbols { get; set; }
public string? NativeMainSource { get; set; }
public bool IncludeNetworkSecurityConfig { get; set; }
public string? KeyStorePath { get; set; }
public bool ForceInterpreter { get; set; }
public bool ForceAOT { get; set; }
Expand Down Expand Up @@ -57,6 +58,12 @@ public ApkBuilder(TaskLoggingHelper logger)
throw new ArgumentException($"MainLibraryFileName='{mainLibraryFileName}' was not found in AppDir='{AppDir}'");
}

var networkSecurityConfigFilePath = Path.Combine(AppDir, "res", "xml", "network_security_config.xml");
if (IncludeNetworkSecurityConfig && !File.Exists(networkSecurityConfigFilePath))
{
throw new ArgumentException($"IncludeNetworkSecurityConfig is set but the file '{networkSecurityConfigFilePath}' was not found");
}

if (string.IsNullOrEmpty(abi))
{
throw new ArgumentException("abi should not be empty (e.g. x86, x86_64, armeabi-v7a or arm64-v8a");
Expand Down Expand Up @@ -172,6 +179,7 @@ public ApkBuilder(TaskLoggingHelper logger)
Directory.CreateDirectory(Path.Combine(OutputDir, "obj"));
Directory.CreateDirectory(Path.Combine(OutputDir, "assets-tozip"));
Directory.CreateDirectory(Path.Combine(OutputDir, "assets"));
Directory.CreateDirectory(Path.Combine(OutputDir, "res"));

var extensionsToIgnore = new List<string> { ".so", ".a", ".gz" };
if (StripDebugSymbols)
Expand All @@ -183,6 +191,7 @@ public ApkBuilder(TaskLoggingHelper logger)
// Copy sourceDir to OutputDir/assets-tozip (ignore native files)
// these files then will be zipped and copied to apk/assets/assets.zip
var assetsToZipDirectory = Path.Combine(OutputDir, "assets-tozip");

Utils.DirectoryCopy(AppDir, assetsToZipDirectory, file =>
{
string fileName = Path.GetFileName(file);
Expand All @@ -199,9 +208,20 @@ public ApkBuilder(TaskLoggingHelper logger)
// aapt complains on such files
return false;
}
if (file.Contains("/res/"))
{
// exclude everything in the `res` folder
return false;
}
return true;
});

// copy the res directory as is
if (Directory.Exists(Path.Combine(AppDir, "res")))
{
Utils.DirectoryCopy(Path.Combine(AppDir, "res"), Path.Combine(OutputDir, "res"));
}

// add AOT .so libraries
foreach (var aotlib in aotLibraryFiles)
{
Expand Down Expand Up @@ -373,6 +393,11 @@ public ApkBuilder(TaskLoggingHelper logger)
if (!string.IsNullOrEmpty(NativeMainSource))
File.Copy(NativeMainSource, javaActivityPath, true);

string networkSecurityConfigAttribute =
IncludeNetworkSecurityConfig
? "a:networkSecurityConfig=\"@xml/network_security_config\""
: string.Empty;

string envVariables = "";
foreach (ITaskItem item in EnvironmentVariables)
{
Expand All @@ -390,6 +415,7 @@ public ApkBuilder(TaskLoggingHelper logger)
File.WriteAllText(Path.Combine(OutputDir, "AndroidManifest.xml"),
Utils.GetEmbeddedResource("AndroidManifest.xml")
.Replace("%PackageName%", packageId)
.Replace("%NetworkSecurityConfig%", networkSecurityConfigAttribute)
.Replace("%MinSdkLevel%", MinApiLevel));

string javaCompilerArgs = $"-d obj -classpath src -bootclasspath {androidJar} -source 1.8 -target 1.8 ";
Expand All @@ -414,7 +440,8 @@ public ApkBuilder(TaskLoggingHelper logger)

string debugModeArg = StripDebugSymbols ? string.Empty : "--debug-mode";
string apkFile = Path.Combine(OutputDir, "bin", $"{ProjectName}.unaligned.apk");
Utils.RunProcess(logger, aapt, $"package -f -m -F {apkFile} -A assets -M AndroidManifest.xml -I {androidJar} {debugModeArg}", workingDir: OutputDir);
string resources = IncludeNetworkSecurityConfig ? "-S res" : string.Empty;
Utils.RunProcess(logger, aapt, $"package -f -m -F {apkFile} -A assets {resources} -M AndroidManifest.xml -I {androidJar} {debugModeArg}", workingDir: OutputDir);

var dynamicLibs = new List<string>();
dynamicLibs.Add(Path.Combine(OutputDir, "monodroid", "libmonodroid.so"));
Expand Down
3 changes: 2 additions & 1 deletion src/tasks/AndroidAppBuilder/Templates/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
<uses-permission a:name="android.permission.INTERNET"/>
<uses-permission a:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission a:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<application a:label="%PackageName%"
<application a:label="%PackageName%"
%NetworkSecurityConfig%
a:largeHeap="true">
<activity a:name="net.dot.MainActivity" a:exported="true">
<intent-filter>
Expand Down