I don't see any error trying your second method: I added XML chapters to MKV file with h.264 video and AAC audio and muxed it:
General
Format : Matroska
File size : 4.06 GiB
Duration : 1h 44mn
Overall bit rate : 5 569 Kbps
Encoded date : UTC 2009-10-27 21:10:46
Writing application : mkvmerge v2.9.7 ('Tenderness') built on Jul 1 2009 18:43:35
Writing library : libebml v0.7.7 + libmatroska v0.8.1
Video
ID : 1
Format : AVC
Format/Info : Advanced Video Codec
Format profile : High@L5.1
Format settings, CABAC : Yes
Format settings, ReFrames : 10 frames
Muxing mode : Container profile=Unknown@5.1
Codec ID : V_MPEG4/ISO/AVC
Duration : 1h 44mn
Nominal bit rate : 5 340 Kbps
Width : 1 280 pixels
Height : 720 pixels
Display aspect ratio : 16:9
Frame rate : 23.976 fps
Resolution : 24 bits
Colorimetry : 4:2:0
Scan type : Progressive
Bits/(Pixel*Frame) : 0.242
Writing library : x264 core 58 svn-736M
Encoding settings : cabac=1 / ref=10 / deblock=1:-3:-3 / analyse=0x3:0x133 / me=umh / subme=7 / me-prepass=0 / brdo=1 / mixed_ref=1 / me_range=24 / chroma_me=1 / trellis=0 / 8x8dct=1 / cqm=2 / deadzone=15,10 / chroma_qp_offset=0 / threads=6 / nr=0 / decimate=0 / mbaff=0 / bframes=4 / b_pyramid=1 / b_adapt=1 / b_bias=0 / direct=1 / wpredb=1 / bime=1 / keyint=250 / keyint_min=25 / scenecut=40(pre) / rc=2pass / bitrate=5340 / ratetol=1.0 / rceq='blurCplx^(1-qComp)' / qcomp=1.00 / qpmin=10 / qpmax=51 / qpstep=4 / cplxblur=20.0 / qblur=0.5 / ip_ratio=1.40 / pb_ratio=1.30 / aq=1:0.6:15.0
Audio
ID : 2
Format : AAC
Format/Info : Advanced Audio Codec
Format version : Version 4
Format profile : Main
Codec ID : A_AAC
Duration : 1h 44mn
Channel(s) : 6 channels
Channel positions : Front: L C R, Rear: L R, LFE
Sampling rate : 48.0 KHz
Resolution : 16 bits
Title : Main Track AAC @ 5.1
Language : English
Menu
00:00:00.000 : :ES.W.A.T. Deployment
00:04:55.000 : :Church Conflagration
00:09:14.000 : :Kill Switch
00:12:24.000 : :New Partner
00:16:14.000 : :No Matter What Happens
00:21:37.000 : :Poseidon Connections
00:24:47.000 : :Stick With Me
00:30:09.000 : :More of a Machine
00:31:55.000 : :Conference Chaos
00:37:10.000 : :Humans Gone Haywire
00:42:40.000 : :Sacrifice and Love
00:46:54.000 : :Cyborg Ban
00:51:06.000 : :Out of Control
00:55:12.000 : :Something Much Bigger
01:01:08.000 : :Feeding Off Briareos
01:05:06.000 : :I Owe You One
01:09:02.000 : :Get Out of My Head
01:11:59.000 : :Mob Mentality
01:15:37.000 : :The Way to Halcon
01:19:26.000 : :Drone Attacks
01:24:00.000 : :Cutting Sentinels Down to Size
01:26:50.000 : :Gate Crashers
01:29:23.000 : :Kill Me While You Can
01:35:14.000 : :Irreplaceable
01:38:10.000 : :Back From the Brink
01:40:06.000 : :End Credits
After that I successfully added ReplayGain info to AAC tracks (applying RG wasn't an option). Perhaps the problem is in the format of your audio file.
And the only problem for me and foobar MKV support is that it doesn't read dual audio streams - it reads only the first audio stream.